- Home /
 
               Question by 
               jmaster2012 · Nov 30, 2014 at 08:58 PM · 
                disablechildren4.6  
              
 
              Disabling Children's GUI from script
How would I disable the children's GUI from the parent's script when a button is pressed?
               Comment
              
 
               
              Answer by YoungDeveloper · Nov 30, 2014 at 09:06 PM
You can get to child by pre-storing it from inspector variable, either get it using Transform.GetChild().
http://docs.unity3d.com/ScriptReference/Transform.GetChild.html
 public GameObject child; //store from inspector
 private void OnGUI(){
     if(GUI.Button(new Rect(0,0,100,30))){
         DisableChild();
     }
 }
 
 private void DisableChild(){
     transform.GetChild(0).gameObject.SetActive(false); //This will get the first child
     //OR
     //child.SetActive(false);
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                