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 5seaton4 · May 08, 2011 at 09:22 AM · guirpgexit

how do you exit GUI

hi im trying to make a logout screen ive made it so when you click on a little x it opens a label with some text and buttons, my yes button takes me back to the main menu i want to know how to make it exit my main label and all the buttons and text here is the code:

public bool exitbuttonclicked = false;

public float exitLabelTextLeft = 300; public float exitLabelTextRight = 7; public float exitLabelTextWidth = 100; public float exitLabelTextHeight = 100;

public float noExitButtonLeft = 738; public float noExitButtonRight = 50; public float noExitButtonWidth = 20; public float noExitButtonHeight = 20;

public float yesExitButtonLeft = 738; public float yesExitButtonRight = 50; public float yesExitButtonWidth = 20; public float yesExitButtonHeight = 20;

public float closeButtonPosLeft = 50; public float closeButtonPosRight = 50; public float closeButtonHeight = 20f; public float closeButtonWidth = 20f;

public float exitBarLabelLeft = 738; public float exitBarLabelRight = 20; public float exitBarLabelHeight = 200; public float exitBarLabelWidth = 200;

 //changes exitbutton clicked to be true
 if(GUI.Button(new Rect(closeButtonPosLeft, closeButtonPosRight, closeButtonWidth, closeButtonHeight),"x", closeButtonStyle)) {
     exitbuttonclicked = true;
 }


 //displays exitbuttonlogout screen
 if (exitbuttonclicked)
 {
     //displays logout box
     GUI.Label(new Rect(exitBarLabelLeft, exitBarLabelRight, exitBarLabelWidth, exitBarLabelHeight), logoutImage);

     //displays the text 
     GUI.Label(new Rect(exitLabelTextLeft, exitLabelTextRight, exitLabelTextWidth, exitLabelTextHeight), "Are you sure you wish to exit?");

     //the yes button
     if(GUI.Button(new Rect(yesExitButtonLeft, yesExitButtonRight, yesExitButtonWidth,yesExitButtonHeight), "Yes")) {
         Application.LoadLevel("Main Menu");
     }
     // the no button
     if(GUI.Button(new Rect(noExitButtonLeft, noExitButtonRight, noExitButtonWidth, noExitButtonHeight), "No")) {
         Debug.Log("No Clicked");

     }
 }

i would prefer c# please i'm not very good at JavaScript

thanks in advance

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 5seaton4 · May 08, 2011 at 09:24 AM 0
Share

i want my NO button to exit the main label and the text and buttons not my yes button.

2 Replies

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

Answer by Cyb3rManiak · May 08, 2011 at 09:49 AM

It's not quite clear, but I'll try and cover all bases in case one of them is what you are looking for.

If you want the No button to just hide the dialogue - it's pretty simple... Just change exitbuttonclicked back to false:

// the no button
if(GUI.Button(new Rect(noExitButtonLeft, noExitButtonRight, noExitButtonWidth, noExitButtonHeight), "No")) {
    Debug.Log("No Clicked");
    exitbuttonclicked = false;
}

When you load a new scene, this script should be destroyed, so you shouldn't have problems with leftover labels or buttons or anything. Is that what you want? If it's not destroyed (if you used Object.DontDestroyOnLoad), you can destroy it manually using Object.Destroy.

    //the yes button
    if(GUI.Button(new Rect(yesExitButtonLeft, yesExitButtonRight, yesExitButtonWidth,yesExitButtonHeight), "Yes")) {
        // This next line will actually destroy this script, unless it was marked as DontDestroy()
        Application.LoadLevel("Main Menu");
    }

If you want to keep the script alive, but don't display anything, you can do something like

public bool bDisplayGUI = true;

public void OnGUI() { if (!bDisplayGUI) return;

 // Rest of your code goes after this
 ...

}

Just take into acount that OnGUI() will run potentially several times each frame, and do nothing, but will waste resources while doing it (since obviously it still needs to be called by Unity).

The next option would be to just disable the script...

//the yes button
if(GUI.Button(new Rect(yesExitButtonLeft, yesExitButtonRight, yesExitButtonWidth,yesExitButtonHeight), "Yes")) 
{
    // This next line will actually destroy this script, unless it was marked as DontDestroy()
    Application.LoadLevel("Main Menu");
    this.enabled = false;
}

I hope that's what you were after...

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 5seaton4 · May 08, 2011 at 11:16 AM 0
Share

thankyou but i just set my exitbuttonclicked to = !exitbuttonclicked.

avatar image
0

Answer by loramaru · May 08, 2011 at 09:45 AM

Are you saying you want the "No" button to hide the logout confirmation that the "x" button opens? If so then just setting exitbuttonclicked back to false should be all you need.

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 Cyb3rManiak · May 08, 2011 at 09:50 AM 0
Share

If only I had clicked the post button 3 $$anonymous$$utes earlier :)

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

No one has followed this question yet.

Related Questions

A node in a childnode? 1 Answer

Top-down 2d Tactical RPG 0 Answers

C# How to Drag and Scale with Mouse Window 0 Answers

Changing GUI.Box opacity 3 Answers

how dose this script look? 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