On collision x or y 2d c#
I am making a game kind of like Mario, and I am making the enemy. The enemy should be killed if the player collides with the enemy on the y axis, but the player should lose health if the player collides with the enemy on the x axis. Is there a way to do this, while still in the OnCollisionEnter2D? Thanks!
Answer by skillbow · Jan 14, 2016 at 06:18 PM
Take a look at this http://answers.unity3d.com/questions/339532/how-can-i-detect-which-side-of-a-box-i-collided-wi.html should be easy to figure out which part of the collider the player is colliding with.
I've actually just thought of an easier way to do this. Create two colliders: Collider 1 will be the main collider and surround your whole player 2) will be set to a trigger and will sit just below your player (make the collider fairly small). Now in your script check for OnTriggerEnter2D and if this is called you know that your player is on top of the enemy.