- Home /
Multicolor GUI Labels/text?
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.
Thanks!
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 ins$$anonymous$$d -- 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 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
Your answer
Follow this Question
Related Questions
Help with coloring a button? 1 Answer
Can I use hexidecimal colors in my GUI? 1 Answer
New UI system 4.6, how to change font color? 2 Answers
guiTexture color half alpha White? 1 Answer
variable before (dot) 2 Answers