I think you would be better off creating a tag and having a “Player” tag and “Road” tag, currently you’re searching (looping) through every game object and finding “Road” which is CPU intensive and same with the others.
Then once you create the tags and tag the game objects you can use something like
if (other.gameObject.tag == “Road” )
{
}
or “Player” depending on where you put the script.
I saw the same thing as js3263854, you’re doing a gameobject.find. this is not correct.
i’ve updated to the code, and added some Debug.log() to verify that the you’re using the Ontrigger.
Do you have the colliders set to be a trigger? if you don’t get any debugs then you don’t have the colliders setup or you don’t have a rigid body
it looks like the bool is working as expected. when the car leaves the ground it changes, when the car hits the ground it changes.
the only thing you could do is to have a bigger trigger collider.
It’s not working exactly. Looks on at some times when the car is on the road…Any chance you have more than 1 object named ground and/or more than 1 collider (trigger) receiving these messages?
You could keep count of the number of triggers you’re inside and use that integer for your calculations (or while counting, if it equals > 0 or 0 that you’re inside, set the bool then).