- Home /
The question is answered, right answer was accepted
destroy child object
i have wrote my script and it comes up with no errors. on collision with "Player" it is suppose to destroy the child object and it is not, here is the script
#pragma strict
function OnCollisionEnter(myCol: Collision){
if(myCol.gameObject.tag == "Player"){
var child = transform.GetChild(0);
GameObject.Destroy(child.gameObject);
}
}
why does this not work?
thanks
Answer by EndUser · Nov 09, 2014 at 09:07 AM
Is it possible to child.gameObject.SetActive=false?
i get one error: Expression 'child.gameObject.SetActive' cannot be assigned to. how do i solve this?
Well, you could peek at docs and find out that SetActive is a function, not a property.
Anyways, the idea is not to destroy, but disable a child game object. Why can't you do it? Is it principal architecture question?
solved it
function OnTriggerStay(trigger : Collider) {
if((trigger.gameObject.tag == "Player") && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E)) {
var child = transform.GetChild(0);
GameObject.Destroy(child.gameObject);
}
}
Answer by Raiden-Freeman · Nov 09, 2014 at 05:24 PM
Try changing Destroy with DestroyImmediate (just for testing, don't leave it to your final code)