- Home /
How do you select a root object from a child's script?
Hi
How do you select a root object from a child's script without doing GameObject.Find("")?
I have a door with a trigger child, and I can't do GameObject.Find, because there are multiple objects with the same name (Building01), and the trigger will only open one door out of, let's say, three buildings.
Besides renaming the building, is there any advice out there that can help me?
Thank you
This is my code for the trigger :
private var door:DoorOpen; var DoorTarget:String="";
function Start() { door=gameObject.Find(DoorTarget).GetComponent("DoorOpen"); }
function OnTriggerEnter(other : Collider) { if(other.gameObject.name=="MainCharacter") { door.openDoor(); } }
Answer by Murcho · Oct 31, 2010 at 11:59 PM
Theres a property available in a transform, "transform.root"
From the docs :
Returns the topmost transform in the hierarchy. (This never returns null, if this Transform doesn't have a parent it returns itself.)
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Getting a Trigger's parent 1 Answer
Trouble with triggers and colliders 1 Answer
Parenting On Trigger not Working? 3 Answers
Instantiate with parent not working? 0 Answers