Hello,
I am here to ask for the same question, after health <= 0 the death animation is playing but the attacker does not pass until my defender destroys completely himself. I tried to set boxcollider2d enable false but it didnt work then i tried to disable the boxcollider on the death animation of defender still its not working.
[SerializeField] float health = 100;
Animator animator;
void Start()
{
animator = GetComponent<Animator>();
}
public void DealDamage(float damage)
{
health -= damage;
StartCoroutine(color());
if (health <= 0)
{
GetComponent<BoxCollider2D>().enabled = false;
StartCoroutine(die());
}
}
IEnumerator die()
{
animator.SetTrigger("isDying");
yield return new WaitForSeconds(3f);
Destroy(gameObject);
}
IEnumerator color()
{
gameObject.transform.Find("Body").GetComponent<SpriteRenderer>().color = Color.red;
yield return new WaitForSeconds(0.3f);
gameObject.transform.Find("Body").GetComponent<SpriteRenderer>().color = Color.white;
}
Thanks for replies.