x


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!

more ▼

asked Feb 02 '11 at 10:01 PM

Daxonovitch gravatar image

Daxonovitch
1 1 1 3

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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.

more ▼

answered Feb 02 '11 at 10:44 PM

yoyo gravatar image

yoyo
7.7k 29 46 97

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.

Feb 02 '11 at 11:44 PM Daxonovitch

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.

Feb 03 '11 at 01:10 AM yoyo
(comments are locked)
10|3000 characters needed characters left

Check manual for GUIStyle

more ▼

answered Feb 02 '11 at 10:07 PM

DaveA gravatar image

DaveA
32.4k 158 176 278

(comments are locked)
10|3000 characters needed characters left

There isn't anything automatic for that.

Here is an old thread that may be useful: FancyLabel

more ▼

answered Feb 03 '11 at 04:05 AM

Molix gravatar image

Molix
5.2k 21 31 70

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5089
x771

asked: Feb 02 '11 at 10:01 PM

Seen: 4062 times

Last Updated: Feb 02 '11 at 10:01 PM