x


GameObject.parent?

Is there a way to get the parent of a GameObject in a script?

more ▼

asked Nov 10, 2010 at 10:18 PM

Intensity116 gravatar image

Intensity116
39 20 16 20

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

1 answer: sort voted first

there is 2 ways

1# use transform.parent for the direct parent above

2# use transform.root witch us the very most top parent of the tree

hope this helps!

note: i am a bit rusty on scripting to this might not be right...

more ▼

answered Nov 10, 2010 at 10:23 PM

3dDude gravatar image

3dDude
2.8k 184 158 182

This gets you the transform of the parent, but not the parent itself.

Oct 21 at 11:24 PM Crissa

@Crissa you can switch back and forth between GameObject and Transfrom by using .gameObject and .transform as appropriate.

In this case use

 transform.parent.gameObject

 // Or

 transform.root.gameObject
Oct 22 at 03:28 AM BoredMormon
(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:

x3656
x663

asked: Nov 10, 2010 at 10:18 PM

Seen: 8173 times

Last Updated: Oct 22 at 03:28 AM