Why does animation only work the first time?

Why does animation only work the first time?

I am creating a game in Unity 3d that is using an animation to move an object. For some reason the animation only works the first time it is accessed and from then on it acts as if it is not being called even though I have debugged and I see that it is being called. Here is the code I use to call the animation:

Which is the first parameter in animator play?

when you call Animator.Play the first parameter is the state name you want to play, layer is the layer index in which this state belong, normalizedTime is the time at which this animation clip should start when play.

How does animator.play work in Mecanim?

In Mecanim your animation is driven by layer of state machine, each one contain states with 1 or many animation. when you call Animator.Play the first parameter is the state name you want to play, layer is the layer index in which this state belong, normalizedTime is the time at which this animation clip should start when play.

How to play and wait for animation / animator to finish?

While both answers should work, another method of doing this with coroutine and the IsPlaying function. You use the coroutine solution if you also want to perform other task after the animation. For the Animation system: The old Unity animation playback system.

How to destroy object after animation in Unity?

But because you can see the shadow of that object, I will destroy it after the animation has played. But how can I do this whit Unity and C#? You could do this by checking the current state of the Animator. Add an additional state that your animation will transition to and then check if the animator reaches this state using AnimatorStateInfo.

How to create a transition in Unity animator?

Make sure to create a transition from to that state back to the default state and that the transition Has Exit Time property be ticked. This is a simple example of how the state machine should look.