Animator: Call script when transition starts (c#)

Hi,
is there a way to call a script when a transition between to states in Animator is starting?

I have this setup:

idle —> moveDown ----> moveUp ----> idle

when I start moveDown it will play this animation and straight after that it will play the moveUp animation and stopping in idle. Now I want to call a script when the animation is switching from moveDown to moveUp to exchange an object.
Is there a way to do this in my c# script?

Thanks

Unity 5 will supposedly let you attach scripts to states, which will be perfect for situations like this.

In Unity 4.x, you can set an Animation Event at the beginning of the animation. The event can invoke a method in your C# script. Or, in your Update() method, you can check Animator.IsInTransition() and Animator.GetNextAnimatorStateInfo() and do your special processing when the transitions occur.

2 Likes

Nice, thank you!

Happy to help!