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 maicondgb · Apr 04, 2014 at 10:36 PM · pausegame

How can I insert Load Level in this Script?

How can I insert LoadLevel in the ''Option'' button at the end?

 using UnityEngine;
 using System.Collections;
 
 public class pauseMenu : MonoBehaviour 
 {
     public GUISkin myskin;
 
     private Rect windowRect;
     private bool paused = false , waited = true;
 
     private void Start()
     {
         windowRect = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 200, 200);
     }
 
     private void waiting()
     {
         waited = true;
     }
 
     private void Update()
     {
         if (waited)
             if (Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.P))
             {
                 if (paused)
                     paused = false;
                 else
                     paused = true;
 
                 waited = false;
                 Invoke("waiting",0.3f);
             }
     }
 
     private void OnGUI()
     {
         if (paused)
             windowRect = GUI.Window(0, windowRect, windowFunc, "Pause Menu");
     }
 
     private void windowFunc(int id)
     {
         if (GUILayout.Button("Resume"))
         {
             paused = false;
         }
         if (GUILayout.Button("Options"))
         {
 
         }
         if (GUILayout.Button("Quit"))
         {
 
         }
     }
 }
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 Gruffy · Apr 05, 2014 at 11:31 AM 0
Share

Hey bud, your answer is below :)

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Gruffy · Apr 04, 2014 at 10:39 PM

Hey bud.

here at your Option menu button you should write...

  if (GUILayout.Button("Options"))
 {
  Application.LoadLevel(0); //this could be a string
  //representing your level name or a number representing its
  //place in your scene build hierarchy
 }


Edit:

Thanks for this dude, but do you know how to stop de scene when I press escape? because when I press escape the pause menu appear but the scene do not stop

This is another question really matey but since you have not marked this as answered, this once I will addend the answer, but in the future, you should understand you have asked a single question and that has been answered for you. Your next question should be a new one or use the site as was intended and search , you would have most definitely found numerous answers regarding this and also the Unify Community pages are riddled with examples pertaining to your questions, both original and addended. Anyway, to allow the game to pause as you wish, you should add a method/call that can change Time.time

So... firstly a new boolean to hold a true or false value, this helps us determine if a button has been pressed or not.

 using UnityEngine;
 using System.Collections;
 
 public class PauseGame : MonoBehaviour {
     private bool isTrue = false;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () 
     {
     
         if(Input.GetKeyUp(KeyCode.Escape))
         {
             if (isTrue)
             {
                 isTrue = false;
                 Time.timeScale = 1.0f;
                 Debug.Log("The Game is now Rolling again " + Time.timeScale.ToString());
 
 
             }
             else
             {
                 isTrue = true;
                 Time.timeScale = 0.0f;
                 Debug.Log("The Game is now paused " + Time.timeScale.ToString());
             }
         }
     }
 }
 

The above is set to trigger when you lift your finger up from the Escape key or back button found on mobile devices.

That should solve your problem with loading a level (& NOW PAUSING WHEN PRESSING "ESCAPE" KEY)on pressing the options button. Take care bud and if that has solved both your questions, then please mark it as an answer as it will help those who do use the search field on this site to obtain a faster result with any similar problems too. Cheers bud Gruffy

Comment
Add comment · Show 7 · 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 maicondgb · Apr 10, 2014 at 03:15 PM 0
Share

Thank you so much dude

avatar image maicondgb · Apr 10, 2014 at 03:23 PM 0
Share

Thanks for this dude, but do you know how to stop de scene when I press escape? because when I press escape the pause menu apear but the scene do not stop

avatar image maicondgb · Apr 10, 2014 at 03:34 PM 0
Share

Thanks for this dude, but do you know how to stop de scene when I press escape? because when I press escape the pause menu apear but the scene do not stop

avatar image BraveVN · Apr 10, 2014 at 04:07 PM 0
Share

when you press escape, use Time.timeScale = 0, then the scene will be pause: https://docs.unity3d.com/Documentation/ScriptReference/Time-timeScale.html

avatar image maicondgb · Apr 11, 2014 at 02:13 AM 0
Share

but this is for java I guess, I want for a C# script

Show more comments

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

23 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Controlling when a script is enabled with another Script 1 Answer

How do I turn this into a Lerp function 1 Answer

Getting all children of 3d model at once 1 Answer

Can't find fix for buggy camera 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 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