Search Unity

GUI Text vs. Label

Discussion in 'Scripting' started by John-B, Mar 3, 2010.

  1. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    I'm not sure what the difference is between using a GUI Text game object and creating GUI labels in an OnGUI function. When should I use one versus the other? Are there any advantages to one or the other, or anything I can do with one and not the other? From what I can tell, both accomplish the same thing, but using a GUI Text object requires less code.
     
  2. Apostle77

    Apostle77

    Joined:
    Apr 25, 2009
    Posts:
    20
    Even though using a GUI text GameObject requires less code, representing the text using the OnGUI() function has its advantages.

    I like to use code because it keeps the scene neater, and I don't have as many unnecessary gameObjects floating around.

    Also, using code makes it much simpler to change the content of the text. You could change color, font size, etc. all in OnGUI(), without having to search through the scene using GameObject.Find
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Using GUIText objects becomes quite painful when dealing with complex GUIs with many elements. However, for simple things like a "Lives: X" readout for example, GUIText is much easier to deal with, particularly when it comes to resolution independence. Using 3DText is another option, which is especially useful when you want to have effects like spinning and zooming text.

    These games that I made a while ago use only GUIText and 3DText, and I would never use OnGUI for things like that. Fractscape uses primarily OnGUI (with some GUITextures), and I would never try to use GUIText/GUITextures to try to make the file requester, for example.

    --Eric
     
  4. zelk

    zelk

    Joined:
    Mar 13, 2009
    Posts:
    246
    I try to find 3dtext in the scripting documentation but cannot find it. Can you give a reference?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's under TextMesh. In the IDE, it's Game Object -> Create Other -> 3D Text.

    --Eric