JVILL
1
I checked the first 10 pages from typing “Unity Destroy child” and all didn’t have the advice I was looking for.
Currently I have:
function OnTriggerExit ( other : Collider )
{
outTile = other.gameObject;
Destroy (outTile.gameObject);
}
But the outTile game object has a child and I want to destroy THAT instead, not other.gameObject but other.gameObject.child (which doesn’t work).
Although the other.gameObject.name can vary greatly, the child always has the same name as its parent + (clone).
Thx!
poday
2
GameObject’s can’t directly access their children but every GameObject contains a Transform which can then access it’s children. Something like:
for (var child : Transform in outTile.transform) {
if(child.name == outTile.name + "(clone)")
{
Destroy(child.gameObject);
}
}
You can reference Unity - Scripting API: Transform as Unity’s documentation on Transforms.
Try this-
function OnTriggerExit ( other : Collider )
{
outTile = other.gameObject;
Destroy (outTile.Find("ChildName"));
}