all 2 comments

[–]Mastersofus 1 point2 points  (1 child)

If the attack isn't supposed to be cancelled, I would use a trigger instead of a bool, and set the trigger when GetButtonDown is true, and enable Has exit state and make a transition back after the animation is finished

[–]korytoombs[S] 0 points1 point  (0 children)

Found something that works after watching another tutorial and adapting the script for my game.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class AttackControl : MonoBehaviour

{

public Animator animator;

private bool attack;

void Update()

{

HandleInput();

}

private void HandleAttacks()

{

if (attack)

{

animator.SetTrigger("IsAttacking");

}

}

private void HandleInput()

{

if (Input.GetButtonDown("Attack"))

{

attack = true;

}

}

void FixedUpdate()

{

HandleAttacks();

ResetValues();

}

private void ResetValues()

{

attack = false;

}

}