# Change animation speed of a 3D model

I am working on a small simulator. There is a 3D character on the screen and it randomly plays an animation (I used animation.PlayQueued(...) command inside a for loop). Now I have added a slider ( GUI.VerticalSlider ) on screen. I want to change the speed of all playing animations of 3D character when change the value of slider.

I know to use animation["animationNane"].speed=xx; but my problem is I have to pass the parameter of animation name that I want to change the speed . but actually I don't want to change the speed of specific animation clip. I want to change the speed of whatever the animation running in my 3d character. How can I change the speed of whatever animation is playing?

From the sounds of it, you want to change the speed of any animation playing. So, essentially, you want to change the speed of all playable animations. The Animation class inherits from IEnumerable, so you can iterate through all clips via a foreach loop.

C#:

foreach (AnimationState state in animation) {
state.speed = 0.5F;
}


Unityscript (Pragma Strict):

for (var state : AnimationState in animation) {
state.speed = 0.5;
}


The above will cause all the clips within the animation object to play at half speed. You can then change the speed back, or to whatever, whenever you need to.

Unity Script Reference - Animation

Unity Script Reference - Animation Scripting (Legacy)