Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to check if animation is playing

Discussion in 'Animation' started by Zimaell, Apr 30, 2023.

  1. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    349
    I have two types of animation - looped and urgent not looped.
    the looped one is played during control, and the urgent one is played when, for example, they hit, fell, in general, this animation interrupts any looped one, while the looped one should not be performed until this urgent one ends.

    Question - how to check when it ended? (to further check whether it is possible to play a looped one)

    I came across a similar example on the web.

    Code (CSharp):
    1. private bool GetPlayAnimation(){
    2.     bool b = false;
    3.     if(animator.GetCurrentAnimatorStateInfo(AnimationLayer).IsName(AnimationName)){
    4.     // if(animator.GetCurrentAnimatorStateInfo(AnimationLayer).IsName("LayerName." + AnimationName)){
    5.         b = true;
    6.         }
    7.     return b;
    8.     }
    but it always gives me a false.