1 분 소요

안드로이드 셋팅 해준다

mac에서 나온 자료는 fbx로 만들어주세요 마야에서 나온 자료는 obj파일로 만들어주세요 → 변환사이트 : Mixamo

image

  • characters에서 zombie라고 검색 후 , 원하는 모델 클릭, 오른쪽에 다운로드 클릭,
  • Format은 FBX for Unity(.fbx) 선택 후 다운로드
  • 다운로드 파일에서 Data-Model폴더에 드래그앤드랍 하면 됨
  • Hierarchy에 드래그앤드랍

  • mixamo에서 animations 클릭하고, Zombie검색 후 원하는 모델 클릭, 여기서 In Place클릭(제자리)
  • 6가지의 동작을 다운로드 후 , animations폴더에 넣어줌

애니메이터만들기 (메카님)

  • animations폴더에 animator controller를 만들어줌
  • zombie 오브젝트에 animator controller를 넣어줌
  • idel을 animation창에 드래그앤드랍
  • parameters에서 anistate라는 int 생성
  • walking과 running 드래그앤드랍 후 , Idle에 transition걸어줌
  • Has Exit Time 체크해제해야함(체크되어있으면 다음동작 버튼을 눌러도 기존 동작이 다 끝난 후에 넘어감)
  • Idel로 가는 화살표 conditions는 Equals에 0번 (Idle을 0, walking을 1, Running을 2로 생각)

image

  • walking으로 가는 화살표는 1번
  • Running으로 가는 화살표는 2번

image

image

  • 모델의 사이즈가 적당한지(사람의 경우 1.5~2미터) 확인하려면 큐브(기본 크기가 1m)와 비교해보면 됨

image

  • 크기가 너무 크다 싶으면 좀비 오브젝트에서, model-select를 누른후,
  • Inspector에서 model - Scale Factor 에서 크기 조정
  • 애니메이션의 scale factor도 다같이 조정해야함
  • 게임오브젝트의 transition의 크기로 조정하면 안됨

image

prefabs

  • zombie오브젝트를 prefabs에 드래그 앤 드랍
  • script에서 zomibeController scirpt를 만듦
  • GUI를 이용하여 애니메이션을 코드로 변경하는 방법
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ZombieController : MonoBehaviour
{

    Animator _ctrlAni;          //처음에 animaotr의 parameter를 가져와야함


    private void Awake()            //내꺼면 start에서 가져오고, 남의것이면 Awake에서 가져오는게 더 편함
    {
        _ctrlAni = GetComponent<Animator>();    // animator 컴퍼넌트를 가져옴
    }

    void Start()
    {
    }

    void Update()
    {
    }

    private void OnGUI()    //GUI를 만들어줌
    {
        if (GUI.Button(new Rect(0, 0, 200, 80), "WALK"))           // 좌표 X=0, Y-0에 W(넓이):200, H(높이):80의 "WALK"라는 버튼을 만들어줌
        {                                                          // 버튼이 눌리면 true를 반환함
            _ctrlAni.SetInteger("AniSate", 1);                    //parameter에서 int형으로 만든 "Anistate"의 1번을 가져옴
        }   
    }
}

↓↓↓enum활용↓↓↓

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ZombieController : MonoBehaviour
{

    public enum eActionState
    {
        IDEL    =0,
        WALK,
        RUN
    }

    Animator _ctrlAni;          //처음에 animaotr의 parameter를 가져와야함


    private void Awake()            //내꺼면 start에서 가져오고, 남의것이면 Awake에서 가져오는게 더 편함
    {
        _ctrlAni = GetComponent<Animator>();    // animator 컴퍼넌트를 가져옴
    }

    void Start()
    {
    }

    void Update()
    {
    }

    private void OnGUI()    //GUI를 만들어줌
    {
        if (GUI.Button(new Rect(0, 0, 200, 80), "IDEL"))           // 좌표 X=0, Y-0에 W(넓이):200, H(높이):80의 "WALK"라는 버튼을 만들어줌
        {                                                          // 버튼이 눌리면 true를 반환함
            _ctrlAni.SetInteger("AniSate", (int)eActionState.IDEL);                    //parameter에서 int형으로 만든 "Anistate"의 1번을 가져옴
        }

        if (GUI.Button(new Rect(0, 85, 200, 80), "WALK"))           
        {                                                          
            _ctrlAni.SetInteger("AniSate", (int)eActionState.WALK);     
        }
        if (GUI.Button(new Rect(0, 170, 200, 80), "RUN"))           
        {                                                          
            _ctrlAni.SetInteger("AniSate", (int)eActionState.RUN); 
        }

    }
}

  • new rect(x,y,w,h)

image

  • 버튼 모습

image

댓글남기기