Id have a bool of “hitPending”, set it when you call the attack animation, unset it in the hit… because… you only need to set the stopattack animation trigger if its actually doing an attack…
as it stands if you have resettrigger stopattack, and then stopattack if you’re walking away at that point it still has the stopattack cued up, hence you also reset it in the attack which you wouldnt need to do.
So mine goes
bool hitpending = false;
private void AttackBehavior()
{
transform.LookAt(target.transform);
timeSinceLastAttack = 0;
hitpending = true;
GetComponent<Animator>().SetTrigger("attack");
}
void Hit() // animation event
{
hitpending = false;
if (target == null) return;
target.TakeDamage(weaponDamage);
}
public void Cancel()
{
target = null;
if (hitpending)
GetComponent<Animator>().SetTrigger("stopattacknow");
}
So mine only gets triggered if you were starting the attack, which leaves you in a cleaner state