- Home /
Any way to check if a animation is halfway done playing?
I know I can check if a animation is currently playing or not (or rather in a specific state) with:
anim.GetCurrentAnimatorStateInfo(0).IsName("Attack")
But lets say I've confirmed I am in state 'Attack', aka, the Attack animation is playing. How do I specifically check if the animation has played 50% of the clip/frames?
Answer by Melodatron · Jan 18, 2017 at 05:35 AM
// For non-looping clips
anim.GetCurrentAnimatorStateInfo(0).IsName("Attack").normalizedTime == 0.5f;
The normalized time is a value between 0 and 1, where 1 = 100% of the clip played. That being said, if you're playing a looping animation, I believe that number can be higher than 1f, indicating the number of times it has been played. If you're working with looping animations then the following is better.
// For looping clips
(anim.GetCurrentAnimatorStateInfo(0).IsName("Attack").normalizedTime % 1f) == 0.5f;
Your answer
Follow this Question
Related Questions
Check Animator State Animation Completed 0 Answers
How to prevent an animation from triggering more than on due to fast clicking? 2 Answers
Using Override Animation Controllers (NOT WORKING) 0 Answers
the animation walk but he still in the same place and rotate left and right on this white circle 0 Answers