# Get the current time of animation using script Unity3d

I want to know the current time of the played animation using script in Unity3d. I tried using currentState.normalizedTime but this time is not the time of the animation, like it's the time of the runtime I think. Any advice please?

Try this:

    int frameNumber = Mathf.FloorToInt(normalizedtimeOfFrame* totalFrames);


You would use AnimationState.time

It can be larger than the length of the animation, so to get the value with this, you would need to modulo with the animation clip length.

float time = currentState.time % currentState.clip.length;


You can also use Normalized Time, but you would have to mulitply the value by the length instead of the animation (AnimationClip.Length)

float time = currentState.normalizedTime * currentState.clip.length;

• But this is the animation time or the run time? Like what if after running my application I didn't play the animation until 5 seconds, would these 5 seconds included when using AnimationState.Time? – Tak Jul 27 '15 at 16:26
• Sorry, I was still editing the question after I posted it. – jgallant Jul 27 '15 at 16:28
• I tried it and it gives this error Error CS0117: 'UnityEngine.Animation' does not contain a definition for 'length' (CS0117) (Assembly-CSharp) – Tak Jul 27 '15 at 16:43
• You have to reference the actual animation instance. Use currentState.clip.length; – jgallant Jul 27 '15 at 16:44
• it is still not working as it gives this error Error CS1061: 'UnityEngine.AnimatorStateInfo' does not contain a definition for 'time' and no extension method 'time' accepting a first argument of type 'UnityEngine.AnimatorStateInfo' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp) – Tak Jul 27 '15 at 16:47