I know how it works. One of the problems in the linked code is that OnCollisionStay
sets the isGrounded
to true and Update
sets it back to false, but Update
runs far more frequent that OnCollisionStay
because OnCollisionStay
is a physics event and will only execute around 60 times per second, while Update
can easily execute at over 500 times per second. You will likely find a lot of flickering in the color because it will be off for more frames than it will be on. It also doesn’t make real sense to continuously turn the color on and off. Set it on collision, reset it when the collision is over.
If the player could die while touching the wall the game would be over, but if it was something like an enemy, you’d need to just grab a reference in Enter, make sure it is still there in Stay, and then destroy the reference in Exit. I don’t believe the exit fires when an object is destroyed, so Stay would be a good place to check if it is still touching.