- Home /
destroying children of a gameobject
in my game i have a defense system when they go to 0 hp the children of the object needs to get destroyed how would i do this?
i have this empty :P
if(CurHealth == 0){
}
the game object cant be destroyed and there are other objects with the same name. just so you know. the object is cached as East and i need to delete the children it has.
Answer by fafase · Apr 29, 2012 at 12:35 PM
You need to access the children: Put this in the parent object:
function GetRidOfChild(){
var script : ScriptNameInChild;
script = GetComponentInChildren(ScriptNameInChild);
script.ChildDestroy ();
}
Then in the child object, place a ScriptNameInChild.js (You can use another name obviously) and
function ChildDestroy(){
Destroy(gameObject);
}
Name the script with a special name so that it odes not mess up with other objects.
I tried it and it works so 100%.
Name it PostBirthAbortion since you're destroying your children. That's a fun script name.
hahaha thank you , was a good explanation as well :)
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Wont destroy child-gameObjects 1 Answer
destroying children also destroys parent itself 4 Answers
Destroy all Objects of a Type in Game 1 Answer
Adding ChildObject 2 Answers