animation.Pause()?

Hi everyone,

I want to know if it’s possible to pause an animation during its execution?

For exemaple i have an animation of an elevator going up and down, when players rich the top and get out of the elevator the elevator stops and when player get back again in the elevator its start the rest of the animation making the elevator go down.

example:

var elevator : GameObject;

function Start(){
     //Here i've stopped all the animations at the beggining of the game;
     animation.Stop();
}

function OnTriggerEnter(){
//It will play the animation when player gets the elevator;  
elevator.animation.Play("elevator");
}

function OnTriggerExit(){
//It will stop the elevator when player gets off
animation.Pause();

//I'm using animation.Stop() in my script today, but when player get back to the elevator it begin the animation all over again, not where it stopped.
}

Does anybody have an ideia or suggestion?

Thanks!

1 Like

This thread might be helpful:
http://forum.unity3d.com/threads/1865-Animation-Pausing

And this is needed section in the script reference:
http://unity3d.com/support/documentation/ScriptReference/Animation.html

In the AnimationsState - speed section, i found this:

// Walk backwards
animation["Walk"].speed = -1.0;

// Walk at double speed
animation["Walk"].speed = 2;
2 Likes

Thanks Baronium,

You’ve just solved my problems : )

Hello, I know this is many many years late but this is for everyone that wants an easy way to pause an animation.
If you are using an animator component and place it on a script such as public Animator anim;
When you want to pause the animation you can say anim.speed = 0; and if you want to make it back to the normal speed you can type anim.speed = 1;

Your welcome to whoever needs it.

38 Likes

Thanks for your reply. We’ll use this method. So sad it hasn’t an easier solution. ^^

Poggers

1 Like

Please stop necro-posting like this.

2 Likes