Unity 3D: Access GUIText object from script

  • Add a GUIText object to the scene:
    Component -> Rendering -> GUIText
    Give it a dummy value (for testing) like „xxxxx“ or something.
    You should see that object floating on top of the scene.
  • Create the script you want to use for the GUIText and put it to the scripts folder in your Unity project. Let’s say it’s called „ChangeVar.js“.
    The content of it can look something like this:

    public var resolutionText : GUIText;
    var i : int;function Start() {
    resolutionText.text = "Hey ya!";
  • In Unity select the GUIText. When it’s selected go to: Component -> Scripts -> „Change Var“ Now the script is attached to the GUIText as you can see it now in the Inspector part. It’s still not working at this point, though.
  • Drag the GUIText object from the Hierarchy and drop it in the Inspector area to „Resolution Text“.
  • From now on you can access that object from the script. If you launch it now with the player the value of the GUIText object will change from „xxxxx“ to „Hey ya!“.

Hope these instructions were helpful!