1. 程式人生 > 實用技巧 >Animator動畫狀態機的簡單使用

Animator動畫狀態機的簡單使用

一.動畫狀態機的使用

  1.動畫狀態機說明

  2.動畫切換箭頭的Inspector面板

  3.動畫的Inspector面板

二.動畫狀態機的使用和指令碼控制

  1.動畫狀態機的使用

在指令碼中,獲取Animator元件,這個元件可以通過SetXXX()方法設定對應引數的值,XXX為引數型別,方法形參為狀態機中引數名和設定的引數值

public class BikerController : MonoBehaviour
{
    public Animator anim;

    float h = 0;
    float v = 0;
    // Start is called before the first frame update
void Start() { anim = GetComponent<Animator>(); } // Update is called once per frame void Update() { h = Input.GetAxis("Horizontal"); v = Input.GetAxis("Vertical"); anim.SetFloat("Horizontal", h);//設定float型別引數Horizontal值為獲取的h值 anim.SetFloat(
"Vertical", v);//設定float型別引數Vertical值為獲取的v值 if (h == 0 && v == 0)//設定bool引數IsIdle為true anim.SetBool("IsIdle", true); else//設定bool引數IsIdle為false anim.SetBool("IsIdle", false); } }