Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.