I’ve been trying to figure this out for hours now and i can’t get it right :C
I have the player object which has an animator which has the controller. In this object i have about 3 different animations and i want to change the speed of one of them.
i know i can do something like: animation[“swing”].speed = speed; but that gives me an error saying that there is no animation attached to player object.
i have one reference to the animator: anim = GetComponent();
and if i do anim.speed = speed; that does increase the speed but to every single clip. So how can i change the animation speed of one single clip?
Thanks in advance!
2 Answers
2
Sorry to necro a thread. But in case others find this thread like me.
Meat’s answer is good. But it also speeds up all the animations on that particular layer.
Unity came up with a solution (finally) after a couple years.
https://forum.unity3d.com/threads/mecanim-change-animation-speed-of-specific-animation-or-layers.160395/page-2
sharing is caring
https://twitter.com/IndieNendoroid
Yes, use
if( animator.GetCurrentAnimatorStateInfo(Layer).IsName("yourAnimation"))
{
animator.speed = animSpeed;
}
Where Layer is the animation layer as int and animSpeed is a float to determine animation speed, where 1 is normal.
This way you can set individual speeds for individual animations.
I’ve never tried it though, I just whipped it up today to answer the same question from about 5 different people 
So, you saw it here first
maybe 
You might wanna refer to this thread that provides a work around. <a href="http://forum.unity3d.com/threads/mecanim-change-animation-speed-of-specific-animation-or-layers.160395/">Mecanim - Change animation speed of specific animation or layers</a> And also refer: <a href="http://answers.unity3d.com/questions/475921/dynamic-mecanim-animation-speedtime.html">Dynamic Mecanim animation speed/time</a> Sometimes a Search does the trick! :-P
– HarshadKanimation["swing"].speed = speed is a legacy call, for Animation component, not Animator, which is Mecanim. I believe you can modify the speed of the whole layer but not an individual animation. To do this you need to alter it within the state machine. To do it per animation simply detect the animation being played and conditionally set the speed of the layer. Alternatively, set up a new state in the Animator which is the same animation, but faster, perhaps with a Blend Tree for a variable range.
– meat5000@meat5000 you just summed up the two links that I provided. OMG! :-0
– HarshadK