1)How could I stop an animation from playing?
I want to play a specific animation, lets say “walk”.
public void AnimateMovement(){
_animator.Play("walk");
}
But, is there a way to stop this same animation?
public void StopMovement(){
_animator.Stop("walk");
}
I tried this but didn’t work, then I tried _animator.animation.Stop but there’s no animation component attached, I made the animations using an animator controller.
2)Is it possible to start an animation from any other frame other than the first?
For example
public void StartMovement(){
_animator.Play("walk", _animator("walk")[2]);
}
First off I’m not an expert on this but the following could be your problem. So your using the “Animator” component not the “Animation” component? That could be your problem. The Animation component you can use your code that you have above and it should work. However, if you use that for the “Animator” component that won’t work unfortunately. You will have to edit the variables that control your walk. For example if your walking your speed > 0.1f so set the speed variable to zero or above to walk or stop.
So for example:
JavaScript:
var anim : Animator;
function SetSpeed(){
anim.SetFloat("speed", 1.3f);//Set the speed variable to 1.3f and the animator takes care of the rest.
}
C#:
public Animator anim;
void SetSpeed(){
anim.SetFloat("speed", 1.3f);//Set the speed variable to 1.3f and the animator takes care of the rest.
}
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<Animator>().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);