Jump to a specific frame in an animation

How can I jump and stop on a specific frame in an animation? I would think this is should be very simple.

Thanks in advance.

Since this is the first post that comes up on Google, here is a slightly more complete answer:

var desired_play_time = 2.3;
animation["MyAnimation"].time = desired_play_time;
animation["MyAnimation"].speed = 0.0;

You use AnimationState.time to jump to a specific time in an animation.

animation["MyAnimation"].time = 5.0;

You can change the time of an animation inside an animator by using the:
animator.Play(“animName”,layer int, NormalizedTime float);

A note: “animName” is actually the named anim state in the animator, so whatever you name it, is what it will call. It also can cause the current animation to jump to this named state. I haven’t found a way to access animations inside blend trees, but you can use this to jump to frames on the total blend tree.

You really shouldn’t need to muck with the speed of the animation

AnimationState clipState = animation.GetClip( "idle" );
clipState.normalizedTime = Mathf.Random( 0.0f, 1.0f );
animation.Sample(); //forces the pose to be calculated
animation.Stop(); // actually commits the pose without waiting for end of frame

Well if you want to do that in Animator then use this

Lets say you want to play the animation from the mid frame .This is how u will do it



getComponent().Play(“Animation_Name”, 0 , (1/total_frames)*frame_number);

For more you can refer here

you can stop animation on any frame you want… for example you want to stop animation at the position of very first frame. just use these line of code

//use this line to stop on very first frame which is 0.0f and the layer is 1