x


changing text color in GUI.Label

i'm trying to change the color of text in a GUI.Label, but i can't figure out how, the only thing i managed to get is make the text invisible...

more ▼

asked Apr 08 '11 at 08:10 AM

Raymond 2 gravatar image

Raymond 2
119 37 40 45

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

3 answers: sort voted first

Take a look at GUISkin

You can set the look of your labels using the current GUI skin if no style is set on your label.

more ▼

answered Apr 08 '11 at 09:10 AM

Meltdown gravatar image

Meltdown
5.6k 18 25 49

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

If you style the label with a copy of GUI.skin.label you can just change the textColor of the particular style mode(s) you want

GUIStyle localStyle = new GUIStyle(GUI.skin.label);
if (somethingBad)
{
   localStyle.normal.textColor = Color.red; 
}else{
   localStyle.normal.textColor = Color.green;
}

that's sort of the quick and dirty way but it works very well most of the time. The 'correct' way is to use custom styles and skins. Many times our buttons don't have text per se so we have to define a separate style with the altered color text.

more ▼

answered Apr 08 '11 at 10:53 AM

raypendergraph gravatar image

raypendergraph
1.6k 15 21 37

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

also GUI.Color, GUI.BackgroundColor, and GUI.TintColor.

more ▼

answered Apr 08 '11 at 10:14 AM

zmar0519 gravatar image

zmar0519
946 59 66 78

(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:

x555
x509
x380

asked: Apr 08 '11 at 08:10 AM

Seen: 3472 times

Last Updated: Apr 08 '11 at 08:10 AM