Change GUILayout.Button font color

Hi,

I have to create a strange keyboard and I have some problems…

GUILayout.BeginArea(new Rect(x,y,2*v/3,b/3));
GUILayout.BeginVertical(“col1”);
GUILayout.BeginHorizontal(“fila 1”);
if(GUILayout.Button(“Q”,GUILayout.Width(t),GUILayout.Height(t))) key=‘q’; if(GUILayout.Button(“W”,GUILayout.Width(t),GUILayout.Height(t))) key=‘w’;

GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUILayout.EndArea();

I need to paint 5 letters in red…

How can I change the GUILayout Button font color?

Thanks!!

If you are using a GUILayout.Button instead of a GUI.Button you can use a GUIStyle:

var style = new GUIStyle(GUI.skin.button);
style.normal.textColor = Color.blue;
GUILayout.Button("Label", style);

You can use GUI.contentColor to give a specific part an other color :

function OnGUI() {

    GUI.Button("Standard Colored")
    GUI.contentColor = Color.red;  // Apply Red color to Button
    GUI.Button("Q button")
    GUI.Button("W button")  //...and so on for the rest Buttons
    GUI.contentColor = Color.withe;  //Make Buttons White color again 
    GUI.Button("White Colored Again")
}

For information, the second solution works in the editor, the first only for in-game UI (which is depreciated and shouldn’t be used AFAIK). :slight_smile: