While working on my inventory GUI, I’ve got NRE that I think I shouldn’t have gotten (in seemingly random place). Here’s the code with marked place, where I got NRE:
bool InventoryButtonWidget(int x, int y, Inventory inv, int index) {
GUIStyle leftLabel = GUI.skin.label;
GUIStyle rightLabel = GUI.skin.label;
leftLabel.alignment = TextAnchor.MiddleLeft;
leftLabel.font.material.color = nameColor; //here
rightLabel.alignment = TextAnchor.MiddleRight;
rightLabel.font.material.color = amountColor; //and probably here (never got so far)
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;
}
nameColor and amountColor aren’t at fault here as those are public Color variables that defaults to Color.Green and Color.Red respectively. So they aren’t null. I have no idea what I’m doing wrong, please help.