Я так понял, это должно выглядеть вот так?
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.name == "AttackHitBox")
{
live--;
StartCoroutine(ResAttack());
anim.Play("HurtAnim");
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.name == "AttackHitBox")
{
StopCoroutine(ResAttack());
}
}
private void Damage()
{
anim.Play("HurtAnim");
live--;
}
IEnumerator ResAttack()
{
while (true)
{
yield return new WaitForSeconds(0.4f);
Damage();
}
}