Daniel Lip
Daniel Lip

Reputation: 11317

How can I color a GUI.Button but also to change the button text size?

var oldColor = GUI.backgroundColor;
GUI.backgroundColor = Color.red;
var searchButton = GUI.Button(new Rect(0, 55, 390, 30), "Search", guiStyle);
    if (searchButton)
        {
        }

This way it's changing the text size to be bigger but then not coloring it in red. If I'm removing the guiStyle it will color the button in red but then the text size will be too small.

Upvotes: 0

Views: 1391

Answers (1)

Ruzihm
Ruzihm

Reputation: 20259

It sounds like you're overwriting properties of the GUIStyle somehow. Get the default button GUIStyle from GUI.skin.button, and make the changes you want from that:

Color oldColor = GUI.backgroundColor;
GUI.backgroundColor = Color.red;

// make copy of default button style 
GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);

// change font size
buttonStyle.fontSize = 18;

bool searchButton = GUI.Button(new Rect(0, 55, 390, 30), "Search", buttonStyle);
if (searchButton) {
    // ...
}

Upvotes: 1

Related Questions