wait for animation to finish unity code example
Example 1: wait time in unity
using System.Collections;
private void Start()
{
StartCoroutine(Wait());
}
IEnumerator Wait()
{
yield return new WaitForSeconds();
}
Example 2: unity wait for animation to finish
if (anim.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
{
}
Example 3: unity call function on animation end
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
GameObject self = animator.gameObject;
MyScript script = self.GetComponent<MyScript>();
Debug.Log("Animation has finished!");
script.SendMessage("MyFunction");
}