# Set Non-Looping Animation Time to Seconds

I have an animation that does not loop. It plays for the default duration (n seconds), then stops on the last frame. This is exactly what I want to have happen, but I want it to play for m seconds, not n seconds. I do not know how long n seconds is.

I have to get it exactly to m seconds, because it is a changing variable. So estimating will not work. I need it to match up exactly with another animation. How can I stretch an animation to last an exact number of seconds?

An easy way if it is a simple animation (rotating gear, a piston, etc) would be to edit your animation to be exactly 1 second long then use the Animator.speed and set it to 1.0f / wanted_seconds, but that's not usable for complex character animations.
You can figure out the length of the AnimationClip ( http://docs.unity3d.com/ScriptReference/AnimationClip.html ) then set the speed to my_animator.speed = my_animator.animation.clip.length / wanted_seconds.