OnTriggerEnter not checking against member boolean..

Hi all,

Having a strange problem. I have an empty game object in the scene with a sphere collider etc. I have triggers working so that object moving around the scene will call OnTriggerEnter etc.

What I would like is to set a bool in the script attached to the trigger object (static position in scene) when the moving object enters and then reset the bool when it exits, i.e:

private bool somethingHere = false;

void OnTriggerEnter(Collider collider)
{  
    // only do action if something isn't already here
    if (!somethingHere)
    {
        // something has triggered this object
        somethingHere = true;
        // do something with object
    }
}

void OnTriggerExit(Collider collider)
{
    // something left this object, allow others now
    somethingHere = false;
}

I have this code in a script attached to some static object in the scene, and the “something” objects are moving around in the scene.

At the moment, for some reason when the first object enters the collider, it triggers fine, but then when another enters, it completely ignores the code and performs the behavior anyway…very strange.

Any help appreciated,
Thanks!

Well! I just tried to set that boolean in the OnTriggerStay function instead:

OnTriggerStay(Collider collider)
{
    somethingHere = true;
}

and this works…

I’m still puzzled as to why it the original method doesn’t work though?

Problem is solved for now though…