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?

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.

AnimationState

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 :)

You can use ‘enabled’ property to stop/pause animations

animator.enabled = false;

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.

If you are using an Animator:

Create a float Parameter(“parametername”) in your Animator and set it to 1.

Select the Animation in the Animator.

In the Inspector, you will see a Speed variable with a Multiplier underneath it.

Check the ‘Parameter’ box and select your Parameter from the drop down list.

In your script(s) you can now use:

yourAnimator.SetFloat(“parametername”, 0.0f);

This will effectively pause the animation clip until you:

yourAnimator.SetFloat(“parametername”, 1.0f);