- Home /
How far though my animation is, via script.
Hi, I didn't manage to any replies last time I tried to get this one answered, I will try and explain the problem a bit better.
I wish to Play animation "A" during this state I would like the user to decide which animation will play next , B or C. at the end of animation A playing , it should then switch to either B or C , which the user decided upon.
I need Animation A to complete before B or C starts.
Here is my Original question:
Hi, I am using Untity 4 and Mecanim to animate a non-humanoid generic object. I would like to find out at runtime, how far through a particular animation my Animator State machine is. if it is say 75% though "dance the Jig", I would like to set a parameter and possibly make a transition to another state.
Any thoughts as I am finding it really difficult to find tutorials / info on mecanim for non-human or generic animation.
Thanks
Answer by kru · Jan 20, 2013 at 02:53 AM
You could create a curve for each animation that is just a straight line from 0 at the start to 1 at the end. Attach it to some parameter such as PercentComplete. Then, in your script's update method, have a line such as
float percentComplete = anim.GetFloat("PercentComplete");
if (percentComplete >= 0.75)
{
// do some event logic to transition to another state
}
Thank you, you are a genius.
simple, elegant bit of lateral thinking.
Your answer
Follow this Question
Related Questions
Animation Does Not Always Play Completely 3 Answers
Help With Animation Play Back - Reverse 1 Answer
Help playing the right animation 1 Answer
Switching from Running Animation to Sliding animation during down swipe 0 Answers
Play animation C# 1 Answer