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?
Answer by Superrodan
Feb 03, 2015 at 11:50 PM
Ok, after finally figuring out what to search for I found an answer here:
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.
Thanks you helped me a lot!
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
22 People are following this question.
How to make a 2d animation repeat
Loop Time through Script 2D 4.3
How to loop an animation in reverse?
Animation keeps playing even with "loop" deactivated.