유니티

04/15 유니티 애니메이션 컨트롤러 연습

박준희 2021. 4. 16. 00:37
728x90

 

1. 캐릭터 모델을 Hierarchy에

2. 애니메이션 컨트롤러 스크립트를 생성하고 캐릭터에 컴포넌트 추가

3. 애니메이션 컨트롤러를 생성하여 캐릭터 모델에 추가

4. 애니메이터에서 blend tree 추가

5. blend tree에 모션 추가

 

AnimationControllerTest.cs

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

public class AnimationControllerTest : MonoBehaviour
{
    public float speed;
    private Animator anim;
    public Button btnReload;
    public Button btnDie;
    // Start is called before the first frame update
    void Start()
    {
        this.anim = this.GetComponent<Animator>();
        this.btnReload.onClick.AddListener(() => {
            this.anim.SetTrigger("Reload");
        });
        this.btnDie.onClick.AddListener(() => {
            this.anim.SetTrigger("Die");
        });
    }

    // Update is called once per frame
    void Update()
    {
        this.anim.SetFloat("Move", this.speed);
    }
}
728x90