Play whole animation over specified time via script

Hello. :wink:

I don’t just want to change the speed of animation. I want to have control of animation state in seconds - e.g. If I put 0.5 in the inspector the animation will play for 0.5s displaying all frames over that time.

For example - character has attackSpeed variable, when its set to 0.5f I want the attack animation play for exactly 0,5 seconds (no matter how many frames are there, all frames must be displayed over that time).

I’m not sure if there is a proper way to do it, or should I just figure out some workaround like calculating frames per second with animation speed? Any ideas?

Thanks for your comment Dibbie. But that’s not what I was looking for.

I found an easy way to achieve it. First, I must assume that animation must be exactly 1 second long. And when I set attack speed to 0.5, which is half a second then animation speed must be doubled - in this case must equal 2 (and now animation also lasts half a second). And if I set attackSpeed to 2 seconds, animation speed must be slowed down to 0.5. This is how I solved it:

	public void SetAttackSpeed(float value)
	{
		attackSpeed = value;
		upperAnim.SetFloat("attackSpeed", 1/value);
	}

The “attackSpeed” parameter in upperAnim is used as a multiplier parameter.