Hi,
i want to ignore the collision between my player and an enemy when the enemy enters the collision of the player.
This works perfectly.
Then i want to unignore the collision when the enemy leaves the collision of the player.
But when i do this, the collision gets ignored and unignored immediatly.
This is my code:
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Gegner")
{
Debug.Log("Collision Started");
Physics2D.IgnoreCollision(other.gameObject.GetComponent<Collider2D>(), this.gameObject.GetComponent<Collider2D>(), true);
}
}
void OnCollisionExit2D(Collision2D other)
{
if (other.gameObject.tag == "Gegner")
{
Debug.Log("Collision Exit");
Physics2D.IgnoreCollision(other.gameObject.GetComponent<Collider2D>(), this.gameObject.GetComponent<Collider2D>(), false);
}
}
This is what my console looks like (the player and the enemy were touching for about 2 seconds):
Thanks for your help!