- Home /
Wait for animation to finish and do something
Im running the snippet of code in a coroutine. It works on the object , however when I try to replay the animation (this is a UI panel that is animated) the second time it isnt working as intended and executes the next line of code before the animation is finished. What is the best way to do this?
//wait for animation to finish
yield return newWaitForSeconds
(animator.GetCurrentAnimatorStateInfo(0).length + animator.GetCurrentAnimatorStateInfo(0).normalizedTime);
//do something
Answer by jeromeatunity · Jul 15, 2020 at 04:09 PM
Hello,
In the past I have used StateMachineBehaviour to execute scripts based on an animation clip state, like progress or exit (complete).
Manual: https://docs.unity3d.com/Manual/StateMachineBehaviours.html
Docs: https://docs.unity3d.com/ScriptReference/StateMachineBehaviour.html
Tutorial (for enemy AI): https://www.youtube.com/watch?v=vxgxcDihld4
Your answer
Follow this Question
Related Questions
Get the coordinate of a tap/click and generate an effect on UI 0 Answers
Help with animator controllers 1 Answer
Problems with player movement animation 0 Answers
What would be the best way to do something based on the animation state of the character? 0 Answers
why I have to anim.getComponent in update() function when I had done in Start () function 2 Answers