- Home /
Weird issue with boolean
Im trying to check, from and external script in a parent, when a trigger collider leaves a surface. I do this with a boolean, but for some reason it always returns false (even when manually set to true) What am I missing?
Parent Script:
         GameObject bottom = GameObject.FindWithTag("Bottom1");
         VehicleBottom other = bottom.GetComponent<VehicleBottom>();
         
         if (bottom == null)
             Debug.Log("Vehicle bottom is not found");
         
         if (other.touchingGround == false)
             Debug.Log ("Not Touching Ground");
         
         if (other.touchingGround == true)
             Debug.Log ("Touching Ground");
Child Script:
     public bool touchingGround = true;
     
         
     void OnTriggerExit(Collider other){
         
         
         touchingGround = false;
         Debug.Log("Vehicle has lost contact with ground");
         }
Because when you are not colliding you are setting it to false:
 OnTriggerExit(Collider other)
 {
 touchingGround = false;
 }
thats why it's always false.
indeed.there is no point in the code you pasted where you set touchingGround to true :D
...other than the declaration
But its supposed to be false when I'm not colliding, I just don't understand why it doesn't turn true when it is colliding(which is most of the time)
where is your :
    OnTriggerEnter(Collider other)
     {
     touchingGround = true;
     }
Answer by Brokenarrow · Jun 13, 2013 at 03:28 PM
I figured it out,I assumed it would go automatically back to true when it started colliding again. A additional OntriggerEnter did the trick. Thanks for pointing out my logical fallacy.
I'm glad you found out your problem :). Now could you mark your answer as solved please :)
Your answer
 
 
             Follow this Question
Related Questions
How Activating a boolean fron another script(C#) 1 Answer
Accessing a boolean from another script with GetComponent (USING C#!) 1 Answer
Select collider for GetComponent? 1 Answer
Do a collider only with certain taged objects 2 Answers
Use trigger with player but have a collider with everything else? 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                