Destroy parent of child gameobject?

So i know destroy(gameobject) will destroy the gameobject.

But my collider is a child of the main controller gameobject…and i want to destroy that part (so child + parent) gameobjects.

So how can i destroy the parent to a gameobject?

2 Likes

You can get the parent of a transform by using

transform.parent

Therefore you need to call

Destroy(transform.parent.gameObject);

Finally, if you only need the parent and not the child component destroyed:

var foo:GameObject;
foo=transform.parent.gameObject;
transform.parent=null;
Destroy(foo);

Why not just use transform.DetachChildren()?

how would you do this with an array?