- Home /
Can I use hexidecimal colors in my GUI?
I'm creating a starting page where a participant enters some information like their name, birth date, and gender. I wanted to use a drop-down menu so they can just select their birth month from a list. I did some research on how to go about doing that in the GUI (I'm using JavaScript for Unity), but the default background on the GUI style is semi-transparent. I wanted to change it so it was more opaque because if there were words under the drop down list, you couldn't read them very well. I did some research on that and successfully changed the normal background as well. My problem is now that with the text being white and/or black, using a gray isn't very aesthetically pleasing and using black will make the previously chosen option unreadable.
I tried playing around with a few other colors like in CSS, but Unity doesn't read those (my go-to test color is teal). I've been trying to find an answer to this before I posted it, and I'm stumped. I can't even find a list of colors that Unity accepts by name. Here is a snippet of the current code.
// Make a GUIStyle that has a solid white hover/onHover background to indicate highlighted items
listStyle = new GUIStyle();
listStyle.normal.textColor = Color.white;//Text colour of list
//Hovering BG
var texHover = new Texture2D(2, 2);
var colorsHover = new Color[4];
for(color in colorsHover)color = Color.white;//Hover BG colour of list
texHover.SetPixels(colorsHover);
texHover.Apply();
//Normal BG
var texBG = new Texture2D(2,2);
var colorsBG = new Color[4];
for(bgColor in colorsBG) bgColor = Color.gray;//Normal BG color of list
texBG.SetPixels(colorsBG);
texBG.Apply();
//Apply Textures to List Style
listStyle.hover.background = texHover;
listStyle.onHover.background = texHover;
listStyle.onNormal.background = texBG;
listStyle.normal.background = texBG;
listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4;
You can see in the 13th line down is where I define what color is in the background of the drop down menu. I'm not too keen on GUI skins to begin with, so I'm quite sure there is something very basic that I'm missing. Basically, I want the background a dark gray.
Here are two screenshots of the GUI list (first one in gray, the second one in black):
Answer by ThermalFusion · Sep 29, 2012 at 11:46 PM
http://docs.unity3d.com/Documentation/ScriptReference/Color.Color.html Create any color using floating point rgba values. If you search the documentation for Color, you will find the list of the prenamed colors here: http://docs.unity3d.com/Documentation/ScriptReference/Color.html You can also use Color32 if you'd rather input colors in the usual 0-255 integer range.
Thank you very much! Exactly what I was looking for.
I knew it would be something basic that I was missing! $$anonymous$$uch appreciated.
For anyone else that comes upon this, here's the documentation for the color32 stuff. http://docs.unity3d.com/Documentation/ScriptReference/Color32.html
That was exactly what I was looking for because I can easily open photoshop, use the color picker to find whatever I need, and the RGB values are listed right there, 0 to 255.