- Home /
Why do my GUI.button Background Colors Not work?
Hello Unity Community, I have created a basic Main Menu with only 3 GUI.button and a grey background. I have set the background color using a variable. When i set the background color for the buttons as the variable on two of the buttons background change to red and the other one still stays as grey and will not change. I have tried everything i can and i have used google but there was no solutions on how i am going to fix this.
Here is my code for my main menu: var MainMenuScene: String;
function OnGUI(){
var oldColor = GUI.backgroundColor;
GUI.backgroundColor = Color.red;
//Make Change Graphics Quality button
if(GUI.Button(Rect(Screen.width /1.5 - 100,Screen.height /2 ,250,50), "Options")){
Application.LoadLevel(MainMenuScene);
Debug.Log("Options: Loaded");
GUI.backgroundColor = oldColor;
}
//Make quit game button
GUI.Button (Rect (Screen.width /1.5 - 100,Screen.height /2 + 50,250,50), "Quit Game");{
Application.Quit();
Debug.Log("Game Closed!");
GUI.backgroundColor = oldColor;
}
//Make quit game button
GUI.Button (Rect (Screen.width /1.5 - 100,Screen.height /2 - 50,250,50), "Main Menu");{
Application.Quit();
Debug.Log("Game Closed!");
GUI.color = oldColor;
}
}
If anyone can check my coding and make sure that it is all correct and tell me how i am going to fix it and make sure the 3 buttons background change.
Thanks in advanced and i will be so grateful for your help, The solution will also be voted as best answer.
Unique
Answer by YoungDeveloper · Feb 13, 2014 at 10:48 PM
If want them all red, there's really no need to reset the color after each button.
function OnGUI(){
GUI.backgroundColor = Color.red;
//Make Change Graphics Quality button
if(GUI.Button(Rect(Screen.width /1.5 - 100,Screen.height /2 ,250,50), "Options")){
Application.LoadLevel(MainMenuScene);
Debug.Log("Options: Loaded");
}
//Make quit game button
GUI.Button (Rect (Screen.width /1.5 - 100,Screen.height /2 + 50,250,50), "Quit Game");{
Application.Quit();
Debug.Log("Game Closed!");
}
//Make quit game button
GUI.Button (Rect (Screen.width /1.5 - 100,Screen.height /2 - 50,250,50), "Main Menu");{
Application.Quit();
Debug.Log("Game Closed!");
}
GUI.backgroundColor = Color.white; //But if i remember correctly you could even not set it back as OnGUI will end anyway
}
Your answer
Follow this Question
Related Questions
Changing Font, Background/Style of GUI Buttons 1 Answer
Main menu help needed (C#) 2 Answers
Menu gui with background image 0 Answers
GUI Texture Changes Position Depending On Screen Resolution? 1 Answer
Setting Scroll View Width GUILayout 1 Answer