Hi! I want to access a Gameobject which is a child of Gameobject "gui". The name of the GO comes from a trigger collision. But all I get is »NullReferenceException«... Here's what I got... Code (csharp): function OnTriggerEnter (col : Collider) { infoBox=GameObject.Find("gui/"+col.name); }
To get the gameObject of the collider use Code (csharp): infoBox = col.gameObject; If you still want to use that option, put Code (csharp): Debug.Log ("gui/" + col.name); to see if its really generating the hierarchy name correctly. .ORG
Thanks! The trigger collection works - but what I need now is more complex: When my FPC hits several trigger colliders (let's say the first one is called "test1") a GUI texture that is also called "test1" should be set to active=true. And here I have that problem: I need "col.name" to get the name of the collider (="test1") - and then change the status of GUI texture "test1". Problem no 1: How can I access the GUI texture when it's within a hierarchy? And how do I add that path to collider.name? Is it "+" ?
The same as you do other Game Objects: Code (csharp): // like this... var tGuiTexture = GameObject.Find("/Foo/Blah/test1"); // or like this... var tGuiTexture = GameObject.Find("test1"); Yes, "+" is what you use to concatenate strings together and the path you pass to the Find() function is provided as a string. Code (csharp): // imagine having three variables... var tFirstToken = "/Foo"; var tSecondToken = "/Blah"; var tThirdToken = "/test1"; // then concatenate those together when calling Find()... var tSomeGO = GameObject.Find(tFirstToken + tSecondToken + tThirdToken);