GameObject.parent?

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

1 Answer

1

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...

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

–

@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

–