HIDE CHILD script - help

what i need to happen: when the player collides with trigger and “B” is pressed the child of that trigger hides.

what does happen: i get an error saying " unknown identifier “child”"

here is my script;

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

}

any help would be great

thanks

Basically you need to get the child transform(s) first before you can tell its renderer to stop rendering. Here are 2 ways:

If you only have one child to make invisible:

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

If you want to make all the children invisible:

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

Sorry, that was a lame response :stuck_out_tongue:

Basically, when you hit the trigger, you need to go get the child/childern then you can do stuff to them.

this post explains how to get the childern from the parent.

Not sure that actually Child exist. Have you tried Transform.GetChild?

Another thing that may help you is try to print the name (or the tag) of the element that is triggering the function, just to be sure that the object has a rendered attached to it.

Regards