- Home /
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!!
Answer by ProGM · Mar 21, 2015 at 06:52 PM
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);
Answer by GameGuy · Apr 12, 2012 at 02:26 PM
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")
}
Answer by Brunni · Jan 06, 2018 at 08:48 AM
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). :)
"first" and "second" are not good references on a page that is arranged by upvote count ....
and ProG$$anonymous$$'s Answer does work very well in the Inspector.
this UI scripting is also not "deprecated" .. it just is way esier to use the new Unity UI but if you like you still can script it all
Your answer
![](https://koobas.hobune.stream/wayback/20220613070233im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can i change the color of GUILayout elements? such as buttons 1 Answer
GUILayout.Button image 0 Answers
How to add GUIStyle to GUILayout Button 1 Answer
How can I create nested buttons ? 2 Answers