- Home /
solved
hide child object script - help
hi all,
i have been playing around with this script for a longtime and it still doesn't work, what is suppose to happen is my player collides with the trigger, "B" is pressed then the CHILD of the object to hide, here is myscript
function OnTriggerStay(trigger : Collider) {
if((trigger.gameObject.tag == "Player") && Input.GetKeyDown(KeyCode.B)) {
renderer.enabled = false;
}
}
how would i change this script so that it hides the child object?
any help/ amendments would be great
thanks
Try adding a Debug.Log("it works"); where you have renderer.enabled = false to see if it even gets that far.
im not familiar with debuglogs, however i do have similar script for sound and that works
if you write Debug.Log("hello"); anywhere, it will print out hello in the Console of the unity editor when it reaches that part of the code.
Answer by Phantomized · Oct 20, 2014 at 12:25 PM
There's nothing wrong with the code.
Try to make sure of the following:
Is the player character tagged as "Player"
Does the player character have a rigidbody attached?(it should)
Does the player have a collider?(it should)
Does the Object to be hidden have a collider?(it should)
is the collider on the object to be hidden set to "IsTrigger"?(it should)
the player is tagged as "Player"
im using a basic charter controller (so no ridged body)
the player does have a collider
the object to be hidden has a collider
the object to be hidden is marked as trigger
I copied your code directly to my unity, and it worked, so you can be certain that it has to do with something else. What you are saying should work in my eyes. Have you put the script on the object that should disappear? Other problems could be multiple colliders on an object etcetera.
ah yer it does work, but it doesnt hide the child object
If you want to hide the child objects then you can do:
foreach (Transform child in gameObject.transform) {
child.renderer.enabled = false;
}
then you need to turn off each child renderer with GetComponentsInChildren()
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
hide object start script 4 Answers
GUI cale and position according to the actual screen resolution. 1 Answer
Detecting whether a player is touching the ground 1 Answer
Raycast Destroys player. 1 Answer