- Home /
Labels aren't colored properly
I can't get coloring labels in my inventory GUI to work.
Here's my code:
public Color nameColor = Color.red;
public Color amountColor = Color.green;
bool InventoryButtonWidget(int x, int y, Inventory inv, int index) {
GUIStyle leftLabel = GUI.skin.label;
GUIStyle rightLabel = GUI.skin.label;
rightLabel.font = GUI.skin.font;
leftLabel.font = GUI.skin.font;
leftLabel.alignment = TextAnchor.MiddleLeft;
leftLabel.font.material.color = nameColor;
rightLabel.alignment = TextAnchor.MiddleRight;
rightLabel.font.material.color = amountColor;
bool temp = GUI.Button(new Rect(x,y,64,64),inv.getItemIcon(index));
GUI.Label(new Rect(x+GUI.skin.button.margin.left,y+64-24,64-GUI.skin.button.margin.left - GUI.skin.button.margin.right,24),inv.getItemName(index),leftLabel);
int amount = inv.getItemAmount(index);
if (amount>1) { //do not draw item amount if we just have one item
GUI.Label(new Rect(x+GUI.skin.button.margin.left, y+GUI.skin.button.margin.top,64-GUI.skin.button.margin.left-GUI.skin.button.margin.right,24),amount.ToString(),rightLabel);
}
return temp;
}
As you can see, nameColor and amountColor defaults to red and green respectively, but when showing it in game, it is white for some reason. Can you help me?
Comment
Best Answer
Answer by TrickyHandz · Oct 05, 2013 at 02:30 AM
Don't call your font materials directly. You need to set the color to the appropriate label state:
leftLabel.normal.textColor = nameColor;
rightLabel.normal.textColor = amountColor;
That should square it all up for you.
Your answer
Follow this Question
Related Questions
MultiColor In 1 Label? 2 Answers
Color.white not so much white... 3 Answers
Change Color For One Line? 1 Answer
How do you change the size and color of a GUI Label in C#? 4 Answers
Drawing 4 GUIButton's with a forloop. Need help changing color? 1 Answer