- Home /
Mecanim: change the animation even though it is not finish in playing
I need to change current animation even though it is not finish in palying. example: I'm in the middle of my slashing animation and then suddenly I press a button and it start to play another animation and stop my slashing animation in its middle of playing.
Note: I'm using mecanim and not Legacy
Thanks in advance
Answer by fafase · Mar 02, 2014 at 10:07 AM
have you tried to change the condition leading to the slashing?
you probably have something of the kind:
anim.SetBool("Slashing",true);
then you can revert that anywhere in your script and start the other anim:
anim.SetBool("Slashing",false);
anim.SetBool("OtherAnim", true);
That should stop the animation and get back to Any State and based on all variables settings, it will start your second animation.
Now if you need to restart the same animation you can use
anim.Play(string stateName, int layer = -1, float normalizedTime = float.NegativeInfinity);
the third parameter defines where to start the animation. 0 should be the beginning.
https://docs.unity3d.com/Documentation/ScriptReference/Animator.Play.html
Answer by mclankyman · Mar 02, 2014 at 10:08 AM
If you look at the image I have posted. say New State 0 is your slashing animation and New State 1 is your new animation.
Set the condition to a bool or something. Which you change to true in your script when you press this button.
For it to jump to the new animation straight away you need to close the start and end arrows of the overlap and move them to the start like I have at the yellow arrow.
This way none of the old animation will be blended with the new one.
Your answer
Follow this Question
Related Questions
Humanoid animation issue 0 Answers
How to play character animation when using A* pathfinding 0 Answers
Animation axis problem 1 Answer
How can I make my animation to cover a particular distance? 0 Answers
Trouble understanding animation 1 Answer