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 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 post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
I am trying to make this color picker script work
Creating SelectionGrid with each button tinted a different color
Changing the color of a GUI element
GUI Colour based on Health?
Tranferring Color from a script to a Gui Box?