You’d split your animation into seperate clips in the importer’s Animations tab, and transition (with zero time if you want no blending) between them. Triggering transitions is easy, strongly recommend watching the official tutorial video, which is quite comprehensive:
But note I’m pretty sure you can’t play animation backwards (i.e. 20-1).
You can trigger transitions from code with variable states, and you can read the normalizedTime of an animation state to know how far along it is (and/or use Curves if you have Pro), but there’s no direct API access to the animator’s State Machine at the moment - we’ve been promised this is coming in an update however so it’s worth keeping an eye on the official unity blogs.
If this topic is still relevant, I can suggest the implementation of backwards animation play. You need to duplicate your animation clip and add it to your state mashine, then in inspector select “speed” and set it to -1. Then animator will go to this state it will play animation backwards. Hope it helps:)
Lord Jesus thank you so much for that. I tried everything to set an animation clip’s wrap mode as ping pong in mechanim. I can do a simple workaround by using the speed -1 trick. THANKS!!!
Mecanim needs much more support for direct script control before it replaces the legacy system, doesn’t it.
There’s all sorts of cases where you want to control the exact position in an animation from code, or sample an animation at a specific point.
The state/transition system makes sense for certain cases, say NPC humanoid characters. But it’s complete overkill for simple things (e.g. opening+closing a door, or moving a few UI elements around), and it’s rather problematic when you want precise script control, and no one-frame-delay/glitch cases.