hide object start script

what i want to do is hide the child at the start, then when “B” is pressed the object appears. however i don’t know how to make it hide at the start. my awful attempt is below:

 function Start (child.renderer.enabled = false;) 
 function OnTriggerStay(trigger : Collider) {
       if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.B)) {
           var child = transform.GetChild(0);
           child.renderer.enabled = true;
      }
  }

i know this doesnt work, can someone show me how to write this properly

thanks

Best approach would be this:

void Start(){
    child.renderer.enabled = false;
}

void Update(){
    if(Input.GetKeyDown("b"))
        child.renderer.enabled = true;
}

function Start ( )
{
var child = transform.GetChild(0);
child.renderer.enabled = false;
}

Well, you didn’t really answered my question. But, let’s assume you have just one. You could use: GameObject.Find(“NameOfYourObject”).renderer.enabled = false;
It’s dirty but should work.

Regarding your code you could also do:
GameObject.FindWithTag(“Player”).transform.GetChild(0).renderer.enabled = false.
Once again, this one is dirty and would not work if you have multiple gameobjects with the “Player” tag.

Finally, the best way is to declare a variable as GameObject. Fill it in the inspector and then call it in start like so:
var myChild : GameObject;
function Start { myChild.renderer.enabled = false; }

  • do you have scripts attached to the ‘child’ that you would use ?
    or else you could just assign the child to a variable via inspector
    and use

    var myChild:GameObject;
    function Start () {
    myChild.gameObject.SetActive (false);
    }

note:this disables the entire child including the scripts on it.

  • or you could try carivorousHam’s answer by setting the renderer checkbox to false(untick) in the inspector when outside playmode and enable the renderer as in your above script