- Home /
Pausing an animation
I don't see a straightforward way to pause an animation. Presumably I first have to log the current frame when I click a button or press a key, and then start the animation again from that frame.
The question being really, how do I get the current frame of an animation? Or is there a better way to pause an animation?
Answer by TheDemiurge · Feb 17, 2011 at 11:37 AM
From the docs under Animation: (no example under AnimationState)
// Make all animations in this character play at half speed
for (var state : AnimationState in animation) {
state.speed = 0.5;
}
so speed = 0 will pause it :)
Answer by Setsuki · Nov 26, 2012 at 10:46 PM
speed = 0 doesn't work in my case, and I have many animations thaat can be playing. In my case, I litteraly want my character to freeze, so I simply used
animation.enabled=false;
Worked like a charm.
Awesome thanks for posting this! Way simpler than the crazy stuff I was trying to do :)
When using animation.enabled=true will it start the animantion again or continue where it was stopped?
@Wessels The answer is yes. It will continue from where it stopped.
When I use this method the animation skips ahead where it would have been when turned back to true. Is anyone else experiencing this?
Just used my one and only rep point on this, dont know how to get them, and probably will never get another. Seriously, this works so well, ;D;D;D
Answer by Hritik-Mahirrao · Jul 01, 2015 at 05:44 PM
You can use 'enabled' property to stop/pause animations
animator.enabled = false;
Answer by Madhur26 · Jun 26, 2017 at 07:57 AM
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class pausescript : MonoBehaviour {
public bool paused;
// Use this for initialization
void Start () {
paused = false;
}
// Update is called once per frame
void Update () {
}
public void Pause(){
paused = !paused;
if (paused) {
Time.timeScale = 0;
} else if (!paused) {
Time.timeScale = 1;
}
}
}
This worked for me.
This is incorrect. This pauses the whole game ins$$anonymous$$d of just the animation.
If the animation is on its own layer, setting the weight to 0.0f is an effective approach and also lerping to zero can have a smoother effect.
Sure, but I don’t see what that has to do with this answer?
Your answer
![](https://koobas.hobune.stream/wayback/20220613104843im_/https://answers.unity.com/themes/thub/images/avi.jpg)