- Home /
Question by
Tulnu · Oct 08, 2021 at 06:56 PM ·
tagscollision2d
Need help with collision2D
When my player collides with the object with the "END" tag it still does the same thing it is supposed to do when it collides with the tilemap.
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Tilemap");
{
FindObjectOfType<EventHandler>().EndGame();
}
if (collision.gameObject.tag == "END");
{
FindObjectOfType<EventHandler>().CompleteLevel();
}
}
}
Comment
Answer by Desti123 · Oct 10, 2021 at 06:14 AM
It could be that your player is colliding with the tilemap at the same time it collides with the object with the end tag. To fix this, just put the "END" if statement first and then make the "Tilemap" if statement an else if statement instead.
void OnCollisionEnter2D(Collision2D collision) {
if (collision.gameObject.tag == "END");
{
FindObjectOfType<EventHandler>().CompleteLevel();
}
else if (collision.gameObject.tag == "Tilemap");
{
FindObjectOfType<EventHandler>().EndGame();
}
}