LoginSignup
9
10

More than 5 years have passed since last update.

Unity2Dメモ3 特定のアニメーション時にだけ何かをする

Posted at

特定のアニメーション時にだけ何かをする

AnimatorStateInfoTest.cs

public class AnimatorStateInfoTest: MonoBehaviour {

    Animator animator;

    // アニメーションの名前(レイヤ.アニメーション名)
  const string RUN_ANIMATION = "Base Layer.Run";

    void Start()
    {
        this.animator = gameObject.GetComponent<Animator>();        
    }


    void Update()
    {
        AnimatorStateInfo stateInfo = this.animator.GetCurrentAnimatorStateInfo(0);

        // Runアニメーション中なら
        if (stateInfo.nameHash == Animator.StringToHash(RUN_ANIMATION))
        {
            Debug.Log("Run Animation");
        }

    }

}
9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10