Hey so I am trying to change a bool based on whether a gameobject is in c collider that is set as a trigger. The problem is that my code works to set my bool to true but it does not set back to false when it is not in the trigger.
void OnTriggerEnter2D(Collider2D ground){
if (ground.gameObject.tag == "ground") {
Debug.Log ("I'm colliding with ground");
onground = true;
} else {
onground = false;
}
}
You need to explain how you are trying to use this functionality. The above code is only going to be called if the two objects are intersecting. I'm guessing that you want to set onground = false in 'OnTriggerExit2D()', or use some other method to detect the ground.
– robertbu