Which of Mulitipe colliders OnCollisionEnter ?
Hi,
I have two sprite objects which i combined in hierarchy. The object is called "Player". When player collides so-called "Egg" object, destroys egg and instantiate a new one. I used OnCollisionEnter2D function via script to detect collision and destroy egg and instantiate a new egg.
But i have got a problem which is sometimes when player collides egg, two egg is being instantiated. It doesn't happen usually but absolutely!
So i suspected about player which has two separate colliders. What i want to do is when player collides egg, destroy the collided egg and create a new one not two or multiple ones!
I hope that i could described my issue succesfully. Looking forward for your help!
Noone helps as usual. Let me dive in details so maybe someone would come and help. 1) I have two objects which are named hat and broom. I set hat as parent of broom and assign "Player" tag both of them.
2) They both have separate colliders. I attach my script to hat since it's parent.
3) When this player (hat and broom) collides egg, egg must be destroyed and another egg must be spawned somewhere.
$$anonymous$$Y PROBLE$$anonymous$$: Sometimes when player collides egg, two eggs are being instantiated! but sometimes. I don't know exactly what causes this to happen.
$$anonymous$$Y SUSPECT: i think, i may have set player incorrect. But i don't know how to fix. I can't move on without solving this problem. I hope someone can help me.
disable the egg collider once it is collieded with the player. hope it solves your problem
Your answer
![](https://koobas.hobune.stream/wayback/20220612214006im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Adding OnCollisionEnter to instantiated object not working properly! 0 Answers
Instantiate object during collision only once 1 Answer
My collision is not being detected or does not produce the desired outcome. 2 Answers
Instantiating from different Sources causes collision inconsistency 0 Answers
OnCollisionEnter Problem 1 Answer