- Home /
Get time when the animation starts in Animator Controller
I have a button which plays an animation whenever I click it. I have defined a bool variable in the animator Editor and set it to the corresponding values whenever I want to play and stop i.e.
private Animator anim;
void Start () {
anim = GetComponent<Animator> ();
}
void OnGUI() {
if(GUI.Button(new Rect(0, 200, 100, 30), "Play"))
anim.SetBool("testBool", true);
if(GUI.Button(new Rect(150, 200, 100, 30), "Stop"))
anim.SetBool("testBool", false);
}
Now when I click "Play" button I want the time started for the start of the animation and when I click "Stop" I want the time at which it was ended.
How do I go about this? I am new to Mecanim, kindly co-operate and help me to get some idea on this.
Answer by vivekkalkur · Mar 03, 2014 at 06:02 AM
I found out the solution. I do not know whether it is an efficient one. Click on the model in the project. Three tabs appear on the Inspector. Click on "Rig" tab and set "Animation type" to "Legacy". By this way you can replace your Animator component to Animation component and provide the animations in that component. Finally through code we can get the time by this snippet :
print ("Start" + animation ["Default Take"].time);
Your answer
Follow this Question
Related Questions
Control Animator time from script 0 Answers
Reusing an Animator Controller for generic animations 4 Answers
How do I set the time of an animation playing in the animator (Mechanum) 5 Answers
[Mecanim] How to manualy set the time on a state by code? 0 Answers
Can I make "has exit time" in the animator disabled by default? 0 Answers