- Home /
How do I stop my animation from looping while I hold down a key?
I need my animation to stop looping while I hold down the Up-Arrow-Key. There are some other functions behind that needs the condition to be just GetKey, NOT GetKeyDown. I also need the animation.play to be on a boolean condition for some other functions behind.
I also tried setting the WrapMode to just Once.
Oh and the animations are attached on the object's Animation Component.
Here's the code:
//I need this to be GetKey, *NOT* GetKeyDown
if (Input.GetKey (KeyCode.UpArrow))
{
upBool = true;
}
//I need the animation.Play to be on bool too, not on the button's if-statement
if (upBool)
{
animation.Play ("UpAnim");
}
//This loops it over and over while I hold down the Up-Arrow-Key but I only want it to play once.
//Once I start holding the Up-Arrow-Key, it will stop looping and just stay on the last frame of the animation.
Thanks :) :) :)
Answer by Pawscal · May 16, 2014 at 04:22 PM
Is animation.Play("UpAnim") is in Update? If so, it's called on every frame, i guess that's why it's looping. Also, make sure you animation is not set to loop in the inspector.
Yeah it's on update, and it's not on loop on the inspector, it's set on once.
Where else can I put the animation.Play with the boolean condition aside from Update?
Your answer
Follow this Question
Related Questions
Animation keeps looping even on WrapMode.Once; 1 Answer
Animations not Transitioning 0 Answers
Programmatically created AnimationClip will not loop 2 Answers
Play a animation on an action? 1 Answer