Is there an [easy?] way to have one label print different words in different colors? I'd prefer not to have to write my own wrapper class to do this, but I'd really like to have some fancy console-type text in my application.
Answer by yoyo
Feb 02, 2011 at 10:44 PM
GUIStyle defines text colour, but labels always use the "normal" GUIStyle. Easiest approach is to override the style colour by setting GUI.contentColor to tint your text. You can then draw different labels with different colours, even though they all share the same style.
I was thinking more along the line of having one label with multiple colors for multiple words.. "You hit an ogre REALLY HARD." with "really hard" in red, the rest in white.
If I use two labels, then I have to write some pretty complex logic to check the size of a label, and stick them together.
Hmm, I don't think there's a way to do that with a single label. Note that GUIStyle.CalcSize makes it easy to measure the size of the text and draw multiple labels. Alternatively you could bake the text into a multicoloured texture instead -- probably ok for smaller amounts of text but would be a pain if you have a lot.
Answer by edwardrowe
Oct 25, 2016 at 05:30 PM
In case anyone digs this post up, Unity has added RichText labels that supports multi colored text:
Answer by DaveA
Feb 02, 2011 at 10:07 PM
Check manual for GUIStyle
Answer by Molix
Feb 03, 2011 at 04:05 AM
There isn't anything automatic for that.
Here is an old thread that may be useful: FancyLabel
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
1 Person is following this question.
GUI Color Selector?
Color Change problem
How do I change the font and color of GUI text?
Material doesn't have a color property '_Color'
New UI system 4.6, how to change font color?