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 RinValak · Apr 04, 2013 at 04:19 AM · gui-button

Draw / don't draw buttons based on boolean variable

I have a feeling I'm missing something really simple, but I can't get this to work. I'm just having a menu item (quit) change to "sure?" after a click.

With the debug log in there it shows quitToggle is staying true, regardless of multiple clicks (it should at least change to false after 1 click, right?). But if I move the debug log to the other side of the variable change, it prints 'false' every click instead. I'm guessing its something to do with the variable not sticking around by the time the GUI updates next frame? Anyway, I'm stumped. Help appreciated, thanks!

I have my "public bool quitToggle = true;" after monobehavior but before void onGUI. I did try swapping it around in various places, but no luck. Sorry, I'm kinda new :D

 // Quit Game Button (ask if you're sure)
         if (quitToggle = true) {
             if (GUI.Button (new Rect (menuPosX+5,menuPosY+110, buttonSizeX, buttonSizeY), "Quit", darkStyle)) {
                 Debug.Log(quitToggle);
                 quitToggle = false;
             }
         }
             
         // Yes I'm sure button
         if (quitToggle = false) {
             if (GUI.Button (new Rect (menuPosX+5,menuPosY+110, buttonSizeX, buttonSizeY), "Sure?", darkStyle)) {
                 System.Diagnostics.Process.GetCurrentProcess().Kill();
             }
         }
Comment
Add comment · Show 3
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 EliteMossy · Apr 05, 2013 at 05:34 AM 0
Share

Why are you using System.Diagnostics.Process.GetCurrentProcess().$$anonymous$$ill(); to kill the game?

Application.Quit(); is designed to do it

avatar image RinValak · Apr 05, 2013 at 10:04 AM 0
Share

Application.Quit was crashing. Looked into it and the best answer I found was "its a problem with unity, wait for an update". So I used that as a workaround. Any advice?

avatar image EliteMossy · Apr 05, 2013 at 10:20 AM 0
Share

Never knew that, always worked when i need it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Graham-Dunnett · Apr 04, 2013 at 11:18 AM

Read up on the assignment operator = and the equality operator ==. Inside an if statement you almost always need the equality operator.

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 RinValak · Apr 05, 2013 at 05:01 AM 0
Share

Thanks much! Learning too many languages at the same time messin' with me.

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

12 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

Related Questions

Creating a pause menu (problem using Time.timeScale) 3 Answers

how made GUIButton for car game 2 Answers

GUI buttons 2 Answers

GUI.button and onClick Terrain 2 Answers

LoadLevel at the end of a sound ! (pb with Coroutine) 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