Search Unity

animation.Pause() ???

Discussion in 'Scripting' started by ImperadorJulioCesar, Nov 25, 2010.

  1. ImperadorJulioCesar

    ImperadorJulioCesar

    Joined:
    Nov 11, 2010
    Posts:
    26
    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:
    Code (csharp):
    1.  
    2.  
    3. var elevator : GameObject;
    4.  
    5. function Start(){
    6.      //Here i've stopped all the animations at the beggining of the game;
    7.      animation.Stop();
    8. }
    9.  
    10. function OnTriggerEnter(){
    11. //It will play the animation when player gets the elevator;  
    12. elevator.animation.Play("elevator");
    13. }
    14.  
    15. function OnTriggerExit(){
    16. //It will stop the elevator when player gets off
    17. animation.Pause();
    18.  
    19. //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.
    20. }
    21.  
    22.  
    Does anybody have an ideia or suggestion?

    Thanks!
     
    Last edited: Nov 25, 2010
    hopetolive likes this.
  2. Baronium

    Baronium

    Joined:
    Aug 21, 2010
    Posts:
    2
    Last edited: Nov 25, 2010
    BootySmashDeluxe and hopetolive like this.
  3. ImperadorJulioCesar

    ImperadorJulioCesar

    Joined:
    Nov 11, 2010
    Posts:
    26
    Thanks Baronium,

    You've just solved my problems : )
     
  4. MegaTeamAJ

    MegaTeamAJ

    Joined:
    Jul 1, 2020
    Posts:
    1
    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.
     
  5. DVFrance

    DVFrance

    Joined:
    Jul 9, 2012
    Posts:
    20
    Thanks for your reply. We'll use this method. So sad it hasn't an easier solution. ^^
     
  6. ShronkusBonkus

    ShronkusBonkus

    Joined:
    May 18, 2022
    Posts:
    1
    Poggers
     
    andrec1250 likes this.
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    Please stop necro-posting like this.