Access guiText from other object.

Hi! Simple question, how do i access a guitext that is attached to a other gameObject than the script. The gameObject name is stored in a variable. Thanks in advance!

Try this

  1. declare a variable for your object. `var object : GameObject;`
  2. declare a variable for the GUIText. `var text : GUIText;`
  3. Find the object you need by using GameObject.Find("thename"). object=GameObject.Find("name");
  4. Access the GUIText component of this GameObject. You can use GameObject.GetComponent(). `text=object.GetComponent(GUIText);`
  5. Now you can change or use the text of this GameObject. `var content=text.Text; text.Text="Hello";`

Add a variable to the script that needs to access the guitext. The variable should be public so you can assign the guitext to it via the inspector.

public GUIText referencetotext;

When you have set this variable to the guitext you can modify the guitext from your script by using the referencetotext.

void Start()

In Javascript the script should look like this

var referencetotext : GUIText;
function Start()

However I don't have much experience with Javascript so I'm not completely sure.