- Home /
Get the current playback time of an animation in Mecanim
Hi,
I'm trying to get the current playback time of a playing animation as a float between 0 and 1 via script. In the legacy animation system, it was a simple enough matter (AnimationState.time). How would I go about it using Mecanim?
Cheers,
Ronan
Comment
Answer by rtumelty · Feb 12, 2013 at 03:34 PM
Never mind. Worked it out.
AnimatorStateInfo currentState = animator.GetCurrentAnimatorStateInfo(animationLayer);
float playbackTime = currentState.normalizedTime % 1;
it worked, but this time showing all animations I have two animations, standing, and walking. how can I get the time a specific animation? for example if (walkingState> 0.5) {? / / Do something }
@marcelobr you can use:
var stateInfo : AnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.nameHash == jump && animTime > 0.1) { //something }