- Home /
Question by
DeathsAbyss · Apr 01, 2014 at 09:28 PM ·
collisioncollider 2d
Collision2D compare the y axis of the object colliding with the object being collided with
Hello there! So what I'm trying to do is I have 2 objects flying at each other, and when they collide I want to determine which is higher than the other by comparing their Y axis with each other, and depending on who is higher remove the other object from the game. I did a little bit of research and saw that maybe Collision2D.transform would be of use but I cant seem to understand how to use it. Any help is appreciated!
Comment
Probably in a onCollision2D event, You need to check the y position of both gameobjects.
something like:
if (GameObject1.transform.position.y > GameOnject2.transform.position.y)
{
Destroy(GameObject1);
}
else
{
Destroy(GameObject2);
}
Your answer