Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by UniqueProductionZ · Feb 13, 2014 at 09:23 PM · javascriptguibuttonsbackgroundmainmenu

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image UniqueProductionZ · Feb 13, 2014 at 10:41 PM 0
Share

Bump, I need this answered urgently!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image UniqueProductionZ · Feb 14, 2014 at 12:40 AM 0
Share

Thankyou so much! It worked!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges