Search Unity

New to Unity and have a maybe obvious question on GUIText

Discussion in 'Immediate Mode GUI (IMGUI)' started by zoonyzone, Mar 3, 2008.

  1. zoonyzone

    zoonyzone

    Joined:
    Feb 21, 2008
    Posts:
    18
    I have a situation where I need to place a few paragraphs of text on a 2d text area that I can scroll. I need to be able to change the color of specific text and change the font sizes.

    In director I did this by writing text to a texture and loading it. But since I am totally new to Unity, I don't see an obvious way to do this (but I am sure I am missing something)

    As an example:

    In the summer of <blue>1941</blue>, the United States......

    Where the text between the <blue> would be blue.

    In addition, the text needs to be over the top of some image like a photo, etc.
    In director I would do this through the layers. I just need to know how to accomplish this since it is a very integral part of the product we are creating.

    --Eric
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can look up GUI.ScrollArea in the docs. Unfortunately, changing the color and font sizes arbitrarily isn't really possible, unless someone knows something I don't. I mean, of course you can change them, but not within the same block of text. Putting it on top of an image is simple; one way is to use GUI.Label for the image and then do GUI.ScrollArea on top of the same area.

    P.S. If you sign your posts like like that here, people might confuse you with me. ;)

    --Eric
     
  3. zoonyzone

    zoonyzone

    Joined:
    Feb 21, 2008
    Posts:
    18
    That was a fast response :D It was like me responding to me (Eric! :D )

    Were do you set the font size?

    Also, do you know of any capability in Unity where you can blit a text string to a texture or something similar? It is VERY important for what we need to do in our application that certain text is different in color.

    My other idea was to somehow in code create a texture file where I can write the text to a texture with a certain color brush, but I am not sure what is supported in the mono framework since I do most coding in applications in Windows .NET.

    I need to dynamically do this since the text I will be loading comes from a database server. I will create the tags in the database text and then just parse it to determine the color of the text. The font size will remain the same throughout (although it would be nice to set attributes like; underline, bold etc)

    --ES (new signature :D )
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's in the import settings for your font. (Single-click on font, then click on Settings...)

    Unfortunately that's a bit tricky...the built-in font handling is one of the few areas where Unity doesn't stand out. It is possible to create textures via programming, so it's possible to make your own font handling system that would do what you want. But it would require quite some development. This doesn't have anything to do with Mono/.NET, but rather the Unity APIs. (Particularly, GetPixels() and SetPixels(), which would be the equivalent of blitting.)

    Maybe somebody else has some better idea.

    --Eric