Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UnityGUI multi line label

Discussion in 'Immediate Mode GUI (IMGUI)' started by Marc, Nov 15, 2007.

  1. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Is there a way to make a multi lined label in UnityGUI? Or disable user input to the TextArea.

    Also does the inspector format strings in some odd way?

    I have tried writing: Line one\nThis is line two in the inspector, but it just puts out the string as it is written in the inspector not interpreting the \n as a new line for the textarea gui element as written in the api example.
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    I often use the Box style for non-editable GUI stuff.
    But it shouldn't make a difference, your GUI label should work over multiple lines - if not, it could be something in the GUISkin setting for labels.
    Try setting the text via script and see if that fixes the problem that you're getting when using the inspector.

    Cheers
    Shaun
     
  3. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Code (csharp):
    1.  
    2. GUI.Label(new Rect(0,20,100,100), "test\ntest2");
    3.  
    The above code does do multi lined labels as expected.

    If pasting the text string "test\ntest2" with the "'s removed or not to the inspector string variable defined by

    Code (csharp):
    1.  
    2. string description;
    3.  
    And using this line to draw the label:

    Code (csharp):
    1.  
    2. GUI.Label(new Rect(0,20,100,100), description);
    3.  
    Does not yield the same result. why?

    Edit: Am using the default gui skin included in unity.
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    \n in the inspector is interpreted as backslash character, followed by 'n'. You need to copy/paste in a line that has the newline in there. To enter one from the keyboard, use ALT-return
     
  5. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Thanks Nicholas!