Both systems support several different possible approaches to waiting until an animation ends before running some code:
- Both can make use of Animation Events, though they are not really the best tool for specifically waiting until the animation ends because it would be quite tedious to set up an event on every animation.
Mecanim
- Constantly check which state is playing using
Animator.GetCurrentAnimatorStateInfo.- This requires the state to have an
Exit Timetransition to actually exit the state and requires you to work with hash codes which aren't particularly user-friendly in order to determine which state is which. - You also need to be aware that it won't enter the desired state immediately, so you actually need to wait for it to enter that state then wait for it to exit.
- This requires the state to have an
- Same as above, but check the value of the state’s
normalizedTimeproperty instead of relying on anExit Timetransition. - Make a
StateMachineBehaviourscript that does essentially the same thing as the previous two options by overridingOnStateExitorOnStateUpdate, add it to the state in question.
Animancer
- End Events: when you call
Playit returns anAnimancerState. Simply register a delegate to itsEvents.OnEndcallback. - Coroutines: if you are inside a coroutine you can
yield returnthat state to wait for it to end. - Manually: store the state in a field and constantly check its
Time, orNormalizedTime. If you're worried about other scripts stopping it, you can also check itsIsPlayingand/orWeightdepending on exactly what you want to achieve.