Friday, December 31, 2021

Check animator is playing or finshed


https://answers.unity.com/questions/362629/how-can-i-check-if-an-animation-is-being-played-or.html?page=1&pageSize=5&sort=votes


 just send your animation name in CurrentAnimation you want to check.

  1. public IEnumerator CheckAnimationCompleted(string CurrentAnim, Action Oncomplete)
  2. {
  3. while (!Animator.GetCurrentAnimatorStateInfo(0).IsName(CurrentAnim))
  4. yield return null;
  5. if (Oncomplete != null)
  6. Oncomplete();
  7. }

calling coroutine

  1. StartCoroutine(CheckAnimationCompleted("Shoot", () =>
  2. {
  3. Animator.SetBool("Shoot", false);
  4. // Your any code
  5. }
  6. ));

No comments:

Post a Comment