Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[Unity 5] Only want animation to play once.

Discussion in 'Animation' started by Plopikoosy, Apr 16, 2015.

  1. Plopikoosy

    Plopikoosy

    Joined:
    Dec 20, 2014
    Posts:
    11
    Hi,

    I currently have a character animation controller set-up that is working fine. However, I have a flip animation set for when the character executes a double jump, and it always keeps looping and flipping until I hit the ground. I have gone into Debug mode and turned wrap mode to Once and unchecked Looping. It hasn't done a thing :/

    Any help would be much appreciated, its driving me crazy.

    Thanks :)
     
  2. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    677
    Can you show some script, how you are calling the flip animation please?
     
  3. romi-fauzi

    romi-fauzi

    Joined:
    Aug 16, 2013
    Posts:
    152
    One thing I can think of is by using a trigger instead of boolean as the parameter that triggers the flip, and then set transition from the flip back to fall/idle animation using exit time, have you done this?
     
  4. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    677
    I use this function for calling once to stop looping ..

    Code (JavaScript):
    1. //              ----------------------------
    2. // triggers the bool of the provided name in the animator.
    3. // the bool is only active for a single frame to prevent looping.
    4. function PlayOneShot (name : String)
    5. {
    6.     _animator.SetBool(name, true);
    7.     yield WaitForSeconds(0);
    8.     _animator.SetBool(name, false);
    9. }
    10. //              ----------------------------
    Then I call it with ..

    Code (JavaScript):
    1. PlayOneShot("flip");
     
  5. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    677
    Or keep calling flip until it's playing ..

    Code (JavaScript):
    1. var flipState = Animator.StringToHash("Base Layer.flip");
    Then call it like ..

    Code (JavaScript):
    1.     while(currentBaseState.nameHash != flipState)
    2.     {
    3.         PlayOneShot("flip");
    4.         yield;
    5.     }
     
  6. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    In the animator, if you double click on a state, you can uncheck the "Loop Time" checkbox to make it play only once.
     
    theANMATOR2b and Mecanim-Dev like this.
  7. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,670
    der_r is right, uncheck loop time on your clip and it should only play once.
     
unityunity