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 AusAndrew19 · Aug 28, 2012 at 07:20 AM · gui

How To Make GUI Buttons Load/Quit

I'm using This Script.

 var doWindow2 = true;
 
 var mySkin : GUISkin;
 var bgImage : Texture;
 
 private var windowRect2 = Rect (0, 20, 350, 500);
 
 private var scrollPosition0 : Vector2;
 private var scrollPosition1 : Vector2;
 private var HorSliderValue = 0.5;
 private var VertSliderValue = 0.5;
 private var Toggle0 = false;
 private var Toggle1 = false;
 private var Toggle2 = false;
 
 //bringing it all together
 function DoMyWindow2 (windowID : int) 
 {
         GUILayout.Space(8);
         GUILayout.BeginVertical();
         GUILayout.Label("Welcome To Project Infinite");    
         
         GUILayout.Label ("Information.", "HeaderText");
         GUILayout.Label ("Project Infinite Is A One Man Team Attempting The Impossible. Enjoy!", "PlainText");
         GUILayout.Space(8);        
         
         GUILayout.Label ("Are You Ready?", "HeaderText");
         GUILayout.Label ("This Is Just A Test..", "PlainText");
     
         GUILayout.Space(190);
         GUILayout.Label ("Play Or Quit?", "HeaderText");
         GUILayout.BeginHorizontal();
         GUILayout.Button("Play.");        
         GUILayout.Button("Quit.");
         GUILayout.EndHorizontal();
         
         GUILayout.EndVertical();
 
 }
 
 function OnGUI ()
 {
 GUI.skin = mySkin;
 
 GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), bgImage);  
 
 if (doWindow2)
     windowRect2 = GUI.Window (2, windowRect2, DoMyWindow2, "");
     //now adjust to the group. (0,0) is the topleft corner of the group.
     GUI.BeginGroup (Rect (0,0,100,100));
     // End the group we started above. This is very important to remember!
     GUI.EndGroup ();
 }

How do i make it so when i click Play it will Application.LoadLevel(1) and when i click quit it will do Application.Quit

I thought it would be.

 if (GUILayout.Button ("Play.")) {
     Application.LoadLevel(1);
 }

 if (GUILayout.Button ("Quit.")) {
     Application.Quit;
 }

But these peices of codes create new buttons instead of activation the already exsisting buttons able to do on click.

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
2
Best Answer

Answer by SolidSnake · Aug 28, 2012 at 08:09 AM

You are doing it wrong..

Simply inside your DoMyWindow2 function when you declare the buttons do the if statements:

 function DoMyWindow2 (windowID : int) 
 {
        GUILayout.Space(8);
        GUILayout.BeginVertical();
        GUILayout.Label("Welcome To Project Infinite");   
 
        GUILayout.Label ("Information.", "HeaderText");
        GUILayout.Label ("Project Infinite Is A One Man Team Attempting The Impossible. Enjoy!", "PlainText");
        GUILayout.Space(8);     
 
        GUILayout.Label ("Are You Ready?", "HeaderText");
         GUILayout.Label ("This Is Just A Test..", "PlainText");
 
        GUILayout.Space(190);
        GUILayout.Label ("Play Or Quit?", "HeaderText");
         GUILayout.BeginHorizontal();
         if(GUILayout.Button("Play."))
         {
            Application.LoadLevel(1);
         }
     
         if(GUILayout.Button("Quit."))
         {
             Application.Quit();
          }
         GUILayout.EndHorizontal();
 
         GUILayout.EndVertical();
 
 }
Comment
Add comment · Show 2 · 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 AusAndrew19 · Aug 28, 2012 at 10:12 AM 0
Share

Thank you for your time and your answer. This correctly fixed my issue with no problem at all. Thank you! Best Regards, Andrew.

avatar image SolidSnake · Aug 28, 2012 at 01:58 PM 0
Share

You are welcome

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

8 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

How to make GUI Text Bigger? 1 Answer

qrest system 1 Answer

How to create a gui button inside an if statement? 1 Answer

GUI.HorizontalSlider not working 2 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