I'm trying to toggle an object on/off via animation to reduce enemy health when using OnTriggerEnter2D to attack and it keeps colliding with the player when the damage box object is on. However, when the player is on the right side of the character, the object only collides once and stops, even though the damage box is still on. enter image description here
private void OnTriggerEnter2D(Collider2D collision)
{
//Debug.Log(collision.gameObject.name);
//var parent = collision.gameObject.transform.parent;
if (collision.gameObject.transform.parent.gameObject.tag == "Player")
{
Debug.Log(collision.gameObject.transform.parent.gameObject.name);
collision.GetComponentInParent<Player>().TakeDamage(damage);
}
}
The player doesn't lose health continuously when standing to the right of the enemy, it only decreases once when it collides and then doesn't split