x


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?

more ▼

asked Jun 27 '12 at 09:15 AM

David1901 gravatar image

David1901
45 6 13 22

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);
more ▼

answered Jun 27 '12 at 09:20 AM

yeoldesnake 1 gravatar image

yeoldesnake 1
549 15 18 22

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3570
x785

asked: Jun 27 '12 at 09:15 AM

Seen: 1049 times

Last Updated: Jun 27 '12 at 09:20 AM