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;
}
}
}
RayJr
October 20, 2014, 3:03pm
2
Sorry, that was a lame response
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.
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
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