Question by
bridgetkacprzyk174 · Jul 26, 2019 at 11:02 AM ·
c#animation2danimator2d-platformer
How do I make my attack trigger work?
I'm trying to play my attack animation and the animator goes to play it but then just goes back to idle without doing anything.
public class playermovement : MonoBehaviour
{
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = 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.GetKey(KeyCode.Mouse0)){
animator.SetTrigger("IsAttacking");
}
}
public void OnLanding ()
{
animator.SetBool("IsJumping", false);
}
private void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, false, jump);
jump = false;
}
}
How do I fix this?
Comment
Answer by xxmariofer · Jul 26, 2019 at 12:33 PM
thats because the bool from Attack -> Iddle is always true, or there is no even a bool for checking. you will have to add exit time or just add a new bool for going from attack -> iddle thats set to false when you attack and set to true after a little delay using invoke or coroutines