I have tried everything to change background color of a labelfield. I have tried to set:
GUI.color
GUI.backgroundColor
GUI.contentColor.
Any of this solutions work. I have tried to create an style for it too assigning a texture for the background, same result… Background stays gray.
Is this a bug?
P.D: I’m using unity 5.3.3
Cheers.
use this extension
public static class Texture2DExtensions {
public static void SetColor(this Texture2D tex2, Color32 color) {
var fillColorArray = tex2.GetPixels32();
for (var i = 0; i < fillColorArray.Length; ++i) {
fillColorArray *= color;*
}
tex2.SetPixels32(fillColorArray);
tex2.Apply();
}
}
then
GUIStyle myStyle=new GUIStyle();
Texture2D tex=new Texture2D(2,2);
tex.SetColor(new Color(0,0,0,255));//r,g,b,a
myStyle.normal.background=tex;
Now use ur style in LableField
EditorGUILayout.LabelField(“bla bla”,myStyle);//black background