8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

8
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");
        }

    }

}
8
9
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
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?