- Home /
GUILayout.SelectionGrid with GUIStyle ignores textColor
Ok, I have a GUILayout.SelectionGrid going that seems to work fine except for one thing. It only ever uses the Normal state for textColor, regardless of whatever I'm doing to the buttons in the selectionGrid. I don't know if I'm doing something wrong, or if GUIStyle doesn't play nice with selection grids or what. I've set up the style using the Unity editor, and assigned it in the following code (where raceSelected is an int, races is a string array, and menuStyle is my GUIStyle obj):
GUILayout.BeginArea(new Rect(65, 5, 150, 550));
raceSelected = GUILayout.SelectionGrid(raceSelected, races, 1, menuStyle, null);
GUILayout.EndArea();
Answer by nsejosh · Jan 15, 2013 at 07:04 PM
Try setting the Background texture- I've noticed that Text Color is ignored unless there's a background texture for the state
THAT'S IT!!! I just spent the last 20 $$anonymous$$utes beating my head against this same thing! Thanks for pointing out what now seems fairly obvious... Unity uses the presence of the background image to know whether to apply or ignore the text color as well!
Answer by frogsbo · Jun 09, 2014 at 07:41 AM
custom grid:
Problem with that, is it uses 1 draw call per button, very slow, for like 10x10 buttons is 100 draw calls. here is a button using whatever texture you want, it returns number of button clicked on your texture:
function OnGUI(){
var gridpixels = 20;//pixels per grid square
var gidxsquares = 12;//num squares in x direction
if (GUI.Button(Rect(320,10,240,60),fctbutton,GUIStyle.none))
{
var xpos = Input.mousePosition.x - 320 ;
var ypos = Screen.height - Input.mousePosition.y -10;
var result = Mathf.Floor(xpos / gridpixels) + Mathf.Floor(ypos / gridpixels)*gidxsquares + 1;//plus 1 at end for not zero first square
//
print (result);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613090817im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I change Toolbar/SelectionGrid selected item's text color? 1 Answer
Styling an individual button in SelectionGrid 0 Answers
Inserting text into GUILayout Box? 3 Answers
Replacing transparency of text with a solid color? 1 Answer
FPS problem with Multi-Colored text on Unity 5 uGUI via Rich Text 0 Answers