Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DayyanSisson · Oct 03, 2011 at 02:52 AM · guiinputbuttonif-statementsgui-button

Unity GUI Style with if Statements

I need to make a menu. With the script I have, if a certain level is unlocked, the GUI button turns red, indicating to the player that they can now play that level. I know to make a button work, the code would be:

 if (GUI.Button (Rect (20,40,80,20), "Level 1")) {
         Application.LoadLevel (1);

But my GUI has this code:

 if(renderMenu && houseNineUnlocked && !explore){
         GUI.backgroundColor = Color.red;
         GUI.contentColor = Color.white;
         GUI.Button(Rect(700,720,500,50), ("House Nine"));

As you can see, there are multiple components to this, and a set of standards has to be met for the GUI to be rendered, and it has specifics too, like background color, and content color. I can't put that into an "if" statement, so how would I do it?

(The only other way I can think of is using textures, but since the textures aren't being worked on at the moment, that's not an option.)

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by syclamoth · Oct 03, 2011 at 03:42 AM

You can nest if statements inside of other if statements! (I know, it's mind-blowing)

 if(renderMenu && houseNineUnlocked && !explore) {
     GUI.backgroundColor = Color.red;
     GUI.contentColor = Color.white;
     if(GUI.Button(Rect(700, 720, 500, 50), "House Nine"))
     {
         Application.LoadLevel(1);
     }
 }

Of course, this will not even render the button if the conditions are not met. Did you want the button to still render, but be greyed out?

Comment
Add comment · Show 5 · 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 DayyanSisson · Oct 03, 2011 at 11:49 PM 0
Share

The if statement I write in my questions is also accompanied by an else if statement too. I actually knew that you can put an if statement inside another if statement, but I didn't think it applied to GUI. Well apparently it doesn't because it's not working. Here an example of what I did this time:

 if(render$$anonymous$$enu && houseOneUnlocked && !explore) {
     GUI.backgroundColor = Color.red;
     GUI.contentColor = Color.white;
     if(GUI.Button(Rect(700, 320, 500, 50), "House One"))
     {
         Application.LoadLevel("House One");
     }
 }

It looks correct to me. The level is in the build settings, I'm getting no error, and all the booleans meet their requirement. I even tested the button, but the button didn't work. It's rendering okay. I'm confused.

avatar image syclamoth · Oct 04, 2011 at 01:52 AM 0
Share

Put some debug.Log just before the Application.LoadLevel bit. See if it is executing those lines!

avatar image DayyanSisson · Oct 04, 2011 at 02:57 AM 0
Share

I did, and nothing happened. Like I said, I tested the button, but the button didn't work. There's something wrong with the script.

avatar image syclamoth · Oct 04, 2011 at 07:05 AM 0
Share

So, your Debug.Log didn't print? I'd have a look at exactly what your button is doing. You say the button definitely renders? I'm telling you, it's nothing to do with nested if statements- there is absolutely no reason why that shouldn't work!

avatar image DayyanSisson · Oct 05, 2011 at 02:28 AM 0
Share

Do you want the whole script so you can test it out yourself?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I make a "move pad" on the screen? (Mobile) 1 Answer

Making GuiButton trigger on ps3 controller input 0 Answers

Cases if a GUI.Button is clicked two or more times?? 2 Answers

GUI RepeatButton can only be clicked once 2 Answers

How can I make GUI button send an input message when I press it? 0 Answers


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