Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How only fire OnCollisionEnter only once for two GameObjects?

Discussion in 'Scripting' started by Kinkku2, Mar 24, 2016.

  1. Kinkku2


    Sep 29, 2014
    Hey! So, I have a bit of a problem: I have two GameObjects with the same script and I have a method I'd like to run from inside their OnCollisionEnter event. When these GameObjects collide, the event fires twice, which is bad. How could I make the method within OnCollisionEnter fire only once while these two GameObjects collide? Thanks.
  2. LeftyRighty


    Nov 2, 2012
    have you tried adding a bool? check the bool is true before doing anything, in the collision code set the bool to false for both this and the collided object. Whichever gets called first will disable the code in whichever is called second. If it's the same script on each of the gameobjects it should work i think.