Question by
bridgetkacprzyk174 · Jul 21, 2019 at 08:40 PM ·
animation2dbool
Getting attack to go back to false?
I'm trying to get my Player have the attack animation go back to idle and I cant get it to work.
public class playermovement : MonoBehaviour
{
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
bool attack = false;
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("IsJumping", true);
}
if(Input.GetKeyDown(KeyCode.Mouse0)){
attack = true;
animator.SetBool("Attacking", true);
}
}
public void OnLanding ()
{
animator.SetBool("IsJumping", false);
}
public void StopAttacking(){
animator.SetBool("Attacking", false);
}
private void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, false, jump);
jump = false;
attack = false;
}
}
The animator just has the "Attack" animation staying lit up. It wont go away unless I jump. What am I missing?
Comment
What is the attack animation transition to? Are you using anim events to do StopAttacking? Can you post an image of your animator?
Also even without the StopAttacking function it still does the same thing.
Your answer
![](https://koobas.hobune.stream/wayback/20220612205245im_/https://answers.unity.com/themes/thub/images/avi.jpg)