Hi to All
I am new here and need to use Animator to know whether one specific Animation is end. Already tried the approach like How can I check if an animation is playing or has finished? (Using Animator/C#) - Unity Answers , still some problems
here is my Animator state
[25998-screen+shot+2014-05-02+at+上午7.11.34.png|25998]
And my code is like this
void Update () {
if (myAnimator.GetCurrentAnimatorStateInfo(0).IsName("TouchingArea"))
{
Debug.Log ("TouchingArea is still playing");
}
else{
Debug.Log ("TouchingArea is done");
}
}
it seems the animation “TouchingArea” is never end. is there anyone who know what is wrong? thanks in advance.
The Animator will remain in the state until it transitions out, so querying the name is going to return true forever, as long this is your only state.
It sounds like you need a new state in the animator. Create a new transition from TouchingArea to the new state when the animation is complete. (Transition condition should be ExitTime with the parameter being 0-1 as a percentage of the animation’s duration). Then you can use the script you’ve written to determine if the animation is still playing, because it will have left that state when it’s done. Of course, you need to make sure the animation for TouchingArea is non-looping.
In general, if an object will be in a state for an unknown amount of time, I try to make sure it’s a looping state. So my door animators would have four states: Open → Closing → Closed → Opening. Even though Open and Closed might just be the last frame of the opening and closing animations respectively.