HI All,

For the last few days i’ve been unable to code a background colour for my On GUI box. I can of course use a custom style and attach the correct colour via a texture but would love to do it with code.
At the moment i can tint texures in the On Gui but not change their exact colour based on code.
Can anyone help or can this not be achieved in unity?
Thanks for your help
You can access GUIStyle properties from code (except for some properties on iOS devices).
Try with duplicating GUI.Skin.box, change the background color and pass this style as parameter :
GUIStyle style = new GUIStyle(GUI.skin.box);
style.normal.background = myTexture;
GUI.Box(new Rect(0,0,100,100), new GUIContent("Test"), style);
If you don’t want to use a predefined set of textures and really want to create your textures from code try to generate textures this way :
Texture texture = new Texture2D(1, 1);
//Set new texture as background
style.normal.background = texture;
//Set the texture color
texture.SetPixel(1,1,Color.white);
// Apply all SetPixel calls
texture.Apply();
[Edit] You can create custom colors with
new Color(red,blue,green);