- Home /
2D collision detection not properly working
Can someone please explain to me why this code:
void OnCollisionEnter2D(Collision2D collision){ if(collision.gameObject.name.equals("deathBox"){ Debug.Log(collision.gameObject.name); } }
is printing out aliveBox. aliveBox is another game object that has a close collider to deathBox, but deathBox should still be getting hit first. Thanks!
Answer by ahmetanteryagiz · Dec 17, 2021 at 08:01 PM
Hello! Can you take a screenshot of the hierarchy? if(collision.gameObject.name.Equals("deathBox")) {Debug.Log(collision.gameObject.name);} cannot print out "aliveBox". Maybe a different function is triggered..
deathBox represents goomba in this picture and aliveBox represents death col.
Your answer
Follow this Question
Related Questions
OnCollisionEnter2D not calling 1 Answer
Polygon Collider 2D weird behaviour when rotating 0 Answers
collision 2D not working on android device 0 Answers
My OnTriggerEnter2D(Collider2D other) not working 1 Answer
How to detect particle collision (ontriggerstay2D )without actually colliding ! 2 Answers