From: http://blog.csdn.net/o_oxo_o/article/details/21325901
In unity, the animation status changes in the mecanim by setting the parameter or converting it according to the end time. However, if the current status is in an excessive state, simply setting parameters cannot achieve the jump of an animation. This is the case I encountered this morning:
I want to convert an animation to runslide by pressing the slide key in the run or runjump state.
As shown in (runjump to runslide are controlled by the slide and jump parameters. Note that attack has no direct relationship with these two States ). The role is currently in a transitional state from runjump to run (generally the time when the role jumps down to the ground after the jump ), at this time, if the player wants to slide (the runslide animation should be executed), it will find that the action cannot be executed.
This is why we often add (! Theanimator. isintransition (0) to avoid this state. However, this method is not applicable to the situations I encountered today. As mentioned above, users cannot play slide results animations. Even worse, if we deal with the height of the collision body when the player presses the slide key (the height of the falling collision body should be reduced, this can be implemented in the mecanim in Unity pro, that is, we do not need to manually modify the collision height in the program. The free version does not have this function .), Then the player will see that the role has not ended the game or has any effect when encountering the obstacle above.
Of course, when dealing with the height of the collision body, we can determine whether the current animation is in the transition state. If yes, we will not narrow down the height. Yes, this will not enable the player to see the embarrassing scenes that encounter obstacles but have no impact, but it still cannot solve the fact that the player has operated the role to make it decline, but the role has not responded to it.
One solution is to force the runslide animation to be executed through the play function of animator after the slide key is detected, no matter whether the current status is transition or not, in this way, you can respond to player decline requests in real time.
thisAnimator.SetBool(eventName, true); if(eventName == "Slide")// && thisAnimator.IsInTransition(0)) thisAnimator.Play("RunSlide");
Here, I used to determine whether the animation is in a transitional state. If yes, the animation is forced to run. However, I later found that in addition to failing to switch to the runslide status during the transition, in the runjump status, when the role lands, it is often unable to set the slide (animator. setbool) is true to go to the slide animation. So I asked the program to play the slide animation as long as the user chooses to slide.
Redirection of mecanim animation in transition state