- Home /
How can I reset a non-looping animation?
Hi there,
I know this is probably a super simple question to answer but I'm close to the functionality I am looking for and can't find the solution I am looking for.
I have created a very simple animation called Roll that rolls a die. I also have a button. I have it so that when you press the button it calls: Animator.Play("Roll")
The first time I tested this, the button worked. It started the roll animation. My problem was the roll animation continued to loop forever. I wanted it to only loop once, and after a google search I found that I needed to uncheck "Loop Time" on my animation. I did that and when I pressed the button it played the animation only once and then stopped in the final frame just like I expected, which was awesome.
The only problem is that after the animation stops the first time I cannot get it to play again by pressing the button again... It just sits at its final frame forever, basically. Is there some sort of reset command I need to call to play the animation again?
Thanks!
Answer by Superrodan · Feb 03, 2015 at 11:50 PM
Ok, after finally figuring out what to search for I found an answer here:
http://answers.unity3d.com/questions/623878/how-to-restart-mecanim-state-animation-or-play-it.html
What I needed to do was create a script with a reference to the animator that called:
myAnimator.Play("Roll", -1, 0f);
This lets me press the button as many times as I want to restart the animation. I hope this helps someone else!
Thank you, your post helped me very quickly. Just wanted to add that if you want to reset the animation on a sprite that only has one animation (like I did), just fill in the first parameter with the sprite's name.
Thanks again, I thought this would take ages to figure out.
Thank you so much! Your post has helped me a lot. I was searching a way to reset some animations and I didn't find until I saw your post.
Your answer
Follow this Question
Related Questions
Animation keeps playing even with "loop" deactivated. 1 Answer
Loop Time through Script 2D 4.3 1 Answer
Animations in the animator not looping 1 Answer
Loop Animation 1 Answer
How to loop an animation in reverse? 0 Answers