- Home /
Stopping an animation from looping at the end?
Hello! So I basically want to stop an animation from looping, but first I want it to finish it's last run, instead of just stopping wherever it happens to be though it. After this, I need to play a different animation. Could somebody tell me how I might go about scripting this? Thank you! -Keavon
Answer by iaanus · Jun 20, 2013 at 03:09 PM
I have seen others suggesting to use CrossFade/CrossFadeQueued, but they don't get the desired effect. I do not want to cross fade nor blend, I want the looping animation to finish its loop and then play the next animation. Eventually, I found a good way to do it. Just in case anyone needs it, here it is:
animation["LoopingAnimation"].wrapMode = WrapMode.Once;
animation.PlayQueued("NextAnimation");
Simple as that. Remember to reset the wrap mode to WrapMode.Loop if you later need to play the looping animation again.
That does the trick ... but ... maybe something changed on those 3 years ^_^U
If the Animation you are trying to stop was played with PlayQueued, Unity will create a duplicate of that animation, so changing the Warp$$anonymous$$ode of the original will not affect the one you want to make it stop.
// Global vars
public Animation myAnim;
AnimationState myState;
void PlayEntrance(){
// Just an entrance animation.
myAnim.PlayQueued ("Entrance");
// Then the Idle animation we want to stop later, we save the AnimationState
myState = myAnim.PlayQueued ("Idle");
}
void PlayExit(){
// We change the warpmode of the saved AnimationState
myState.wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;
// And put the new animation in.
myAnim.PlayQueued ("EXit");
}
Answer by Justin Warner · Dec 07, 2010 at 05:14 AM
http://unity3d.com/support/documentation/ScriptReference/Animation-clip.html
Work that in, then after the yield, play whatever animation you want...
=) All the best!
Thank you, but how do I use that? I am relatively new to Javascripting. First of all, I don't want to make it wait for a certine amount of time, as it appears this example is doing, but then what do I replace with "animation," "clip," "name," and, "length?" Thank you! I would really appreciate it!
Answer by Cyb3rManiak · May 11, 2011 at 12:05 PM
You can use Animation.CrossFadeQueued to play several animations in a row.
If you don't really understand the basics, I suggest you check out the character-animation example project and the 3d-platform-game tutorial, and read about how the animation in Unity works from the docs.
Basically, if I remember correctly, you do something like:
animation.CrossFadeQueued("shoot", 0.3, QueueMode.PlayNow);
animation.CrossFadeQueued("jump", 0.3, QueueMode.CompleteOthers);
animation.CrossFadeQueued("crawn", 0.3, QueueMode.CompleteOthers);
Your answer
Follow this Question
Related Questions
Stop animation when button is released 2 Answers
Animation loop stop? 1 Answer
how to stop animation loop? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Loop Animation In Script? 2 Answers