how to stop an animation at a specific frame on animator?
Hi, I've seen all the forum topics on this subject but in my case the situation is a little bit different and I don't know what to do :(
If someone helps me, I would be very grateful :)
I have an animator that when it is in the state of attack, it performs an animation (the attack animation).
What I want is when the attack button (space) is pressed (only once), the attack animation normally plays. "But", when I press the space button (without dropping it), the animation stops at a certain specific Frame and, When I release the space button, the animation continues from the point where it stopped.
My code is almost identical to this (has more things), and i want something like that/this:
public class PlayerControls : MonoBehaviour {
private Animator anim;
void Awake() {
anim = GetComponent<Animator>(); }
void FixedUpdate() {
Animation();
}
void Animation() {
if ( Input.GetKeyDown(KeyCode.Space) )
{
anim.SetBool("Attack", true);
Attack();
}
else if ( Input.GetKey(KeyCode.Space) )
{
anim.SetBool("Attack", true);
anim.Stop( *at frame 35 of 68* );
if (Input.GetKeyUp(KeyCode.Space)) {
anim.Play(); // play from the frame 35 (when it stopped)
}
}
}
Answer by samra2494 · Mar 07, 2019 at 05:51 AM
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<Animator>().PlayInFixedTime("ClipName",1,0.0f);
Your answer
Follow this Question
Related Questions
Stop Animation when bool is false? 0 Answers
How do I puse an animation? 1 Answer
How to set the blend tree threshold value during run time? 0 Answers
Why default animation state rewrites scale of an object? 0 Answers
Animation Running Game 0 Answers