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!

About Dominik
Currently working as an Android/iOS developer for Cineman, Switzerland. Owner of http://www.ukon.ch and https://play.google.com/store/apps/details?id=com.cheatdatabase

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

You must be logged in to post a comment.