How to stop animation from playing in c#.

How to stop animation from playing in the animator in c# script. Without using myAnimator.SetBool(“Animation”, true); - because I already know how to use this.

Hello @DiamondMC102.

To stop an animator from playing the animation, simply, disable the animator component using this code:

myAnimation.gameObject.GetComponent<Animator>().enabled = false;

I have also found that disabling the gameObject itself will also stop the animation from playing until it is enabled again.

I hope you find this information helpful. And don’t hesitate to reply back if you have any further enquirers or need more assistance.

All the best.

ok but what if I just want to stop one animation and not the whole controller

you can stop animation on any frame you want… for example you want to stop animation at the position of very first frame. just use these line of code
//stop animation … on first frame
gameObject.GetComponent().Rebind();
please try this above line if it not work for you . try the blow line of code
OR
//use this line to stop on very first frame which is 0.0f and the layer is 1
gameObject.GetComponent().PlayInFixedTime(“ClipName”,1,0.0f);

super normal, to stop an animation we must to desactivate the component.
Stop, play or repeat looks so weird to use with animations. ok

You can set speed multiplier to 0. Create a new parameter in animator window. Then click on the animation in animator window. Click on the parameter button next to Multiplier(below Speed). Then change it in the code:

m_Animator.SetFloat("speedMultiplier", 0f);

//For playing the animation
gameObject.GetComponent().Play();
//or
gameObject.GetComponent().enable = true;

//For stop the animation
gameObject.GetComponent<Animator>().enabled = false;

A idea for Stop animation > Need Apply in Unity Engine.

For Animation Starts:

if (Input.GetKeyDown(KeyCode.W))
{
Example.Play(“Animation”);
}

For Animation Stop:

if (Input.GetKeyOut(KeyCode.W)) > GETKEYOUT
{
Example.Stop(“Animation”);
}