How can I find what current frame an animation in progress is at?
For example, shiva3d has this command: animation.getPlaybackCursor ( object, layer ) which returns what the current frame of the animation in progress is at.
I’ve dug through the docs and forum and haven’t been able to find anything.
Sorry, but Unity3d currently does not have this function.
You can request it from the Wish List side of the forums if you want, and hopefully someone important will see it.
But there may be other solutions such as animation blending with animation.CrossFade (animationName, crossFadeTime); for example if that’s what you need.
Then to convert from time to frame you multiply by your animation’s framerate. Just note that because of variable framerates, you’re not guaranteed to be exactly on a frame so use greater than / less than to check if you’ve passed a given frame or are between the two frames you’re looking for.
eg:
//if animation is between frames 10 and 15
if (animation["attack"].time > 0.333 < animation["attack"].time < 0.5) {
//do something interesting
}
Thanks! That’s perfect. I used to use a range in shiva3D because I couldn’t count on a frame not getting dropped and the code being skipped. So a range is just fine with me.
I thought “.time” just returned the length of the anim. Glad to see that I was wrong.
I used to be able to just play the animation with the wrap mode set to LOOP but with Unity4 the animation would pause a few seconds before starting again. I noticed that if I stopped the animation it would play from the beginning again…so I just added this code in the update function… when it gets to frame 30 (then end of the walk animation above) it just stops. The result is the animation loops the way it should again. I do find it annoying to add this code in though.
if (Andy.animation["walk"].time*Andy.animation["walk"].clip.frameRate >=30){
Andy.animation.Stop("walk");
}
Thank you for your effort, but please don’t reply to such old threads. The post is a dozen years old, the Unity has changed significantly since the question was asked. Closed.