Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Checking if a specific animation is playing in animator!!

Discussion in 'Scripting' started by Jeremie-de-Vos, Apr 10, 2017.

  1. Jeremie-de-Vos

    Jeremie-de-Vos

    Joined:
    Jun 5, 2015
    Posts:
    120
    Hey,
    I trying to check if a animation has stopped playing in a animator and then execute some code.
    But, it's not working.

    What did i do wrong?
    And how can i fix it?

    All help is Appreciated!!

    Code (CSharp):
    1.                
    2. if (Input.GetKeyDown(window[i].EnterWindow))
    3.                 {
    4.                     if (window[i].UseAnim)
    5.                         window[i].Window.GetComponent<Animator>().Play(window[i].OpenAnimName);
    6.                 }
    7.  
    8.         if(Input.GetKeyDown(ExitWindow))
    9.         {
    10.             for (int i = 0; i < window.Count; i++)
    11.             {
    12.                 if (window[i].FreezTime_b == true)
    13.                     FreezTime(1);
    14.  
    15.                 if (window[i].UseAnim)
    16.                 {
    17.                     window[i].Window.GetComponent<Animator>().Play(window[i].CloseAnimName);
    18.  
    19.                     if (!window[i].Window.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName(window[i].CloseAnimName))
    20.                     {
    21.                         window[i].Window.SetActive(false);
    22.                         window[i].IsOpen = false;
    23.                     }
    24.                 }
    25.                 else
    26.                 {
    27.                     window[i].Window.SetActive(false);
    28.                     window[i].IsOpen = false;
    29.                 }
    30.  
    31.                 CanOpenWindow = true;
    32.  
    33.                 Cursor.lockState = CursorLockMode.Locked;
    34.                 Cursor.visible = false;
    35.             }
    36.         }
    37.  
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
  3. Jeremie-de-Vos

    Jeremie-de-Vos

    Joined:
    Jun 5, 2015
    Posts:
    120
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Sorry, you have a script with code but can't use that code to check? I admit my knowledge is a little lacking with the animator, but I don't follow that..
    One last suggestion that may or may not be useful.
    You can add an event to the animator/animation thing.
    I mean, unless this is something you can't add for a similar reason, it might help?
    https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html
    If suitable, you could call your method directly with such an event.
    If that doesn't work, all I can say is good luck & I hope you find something that works lol :)
     
  5. Pengocat

    Pengocat

    Joined:
    Dec 7, 2016
    Posts:
    140
  6. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    @Jeremie-de-Vos Hmm it seems like a bunch of the code is missing (it's referring to non-standard Unity things that are not in the code snippet), so we can't really tell what your code is doing 100%.

    Are you looking to do this during play mode, or in an editor script?