- Home /
Checking boolean state using raycast
How i can check if boolean is false on a script that is on a gameobject that my raycast is pointing at? So I want to get boolean state using raycast. Raycast because I want to select exactly the right object because I have many of those same objects in the scene and I cant check boolean from all of them of just random one.
 function Update () {
 var hit:RaycastHit;
 var ray:Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 if(Physics.Raycast(ray,hit, 1000)) {
 if(Boolean is false in a script that my raycast is pointing at){ //<-------------------------
 if(Input.GetMouseButtonDown(0)){
 Debug.Log("Select target");
 hit.collider.gameObject.SendMessageUpwards("target");
       }
     }
   }
 }
Any idea? I hope you got the idea, I give more info if needed.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by ziv03 · Dec 23, 2013 at 03:46 PM
scripts are added to gameobjects as components.. if you want to access another script you can use GetComponent.
if your gameobject script is blabla.js and it has a var called boolBla (in c# it has to be public, not sure about JS) then:
 if(!hit.collider.gameObject.GetComponent("blabla").boolBla)
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                