• 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
Question by Guzaii · Sep 08, 2013 at 02:03 AM · guigame

Pause Menu

Im trying to make a pause menu. Ive gotten all this:

 var guiSkin : GUISkin;
 var MainMenu : Rect = Rect(10, 10, 200, 200);
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnGUI () {
 if(guiSkin != null)
     GUI.skin = guiSkin;
 GUI.Window(0, MainMenu, TheMainMenu, "Pause Menu");
 }
 
 function TheMainMenu () {
 if(GUILayout.Button("Main Menu")){
 Application.LoadLevel("MainMenu");
 }
 if(GUILayout.Button("Restart")){
 Application.LoadLevel("InGame");
 }
 if(GUILayout.Button("Quit")){
 Application.Quit();
 }
 }


Only problem ive got left, and have no clue how to fix.. How can i make it actually Pause the game? How can i make it Show/Hide once i press Esc?

Comment
ZOM585

People who like this

1 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 StarArt · Dec 13, 2015 at 04:23 PM 0
Share

So How to change GUI Button with Custom Sprites?

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by DeveshPandey · Sep 10, 2013 at 10:58 AM

 var isPause = false;
 
 function Update () {
  if( Input.GetKeyDown(KeyCode.Escape))
    {
       isPause = !isPause
       if(isPause)
          Time.timeScale = 0;
       else
          Time.timeScale = 1;
    }
 }
 
 function OnGUI()
 {
    if(isPause)
        GUI.Window(0, MainMenu, TheMainMenu, "Pause Menu");
 }
Comment
erdavis
MajdHamada
gura1
Mathilorian
kingofbananas
ZOM585
RobyandLuca

People who like this

7 Show 8 · 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 Guzaii · Sep 10, 2013 at 11:03 AM 0
Share

Thanks for the help :) But when i use this, then i get this: "Assets/Pause Script.js(17,32): BCE0005: Unknown identifier: 'TheMainMenu'." and: "Assets/Pause Script.js(17,22): BCE0005: Unknown identifier: 'MainMenu'."

avatar image DeveshPandey · Sep 10, 2013 at 11:07 AM 0
Share

which line pointing this errors? Can you show me your Pause Script.js?

avatar image DeveshPandey · Sep 10, 2013 at 11:15 AM 1
Share

I think you are not using

var MainMenu : Rect = Rect(10, 10, 200, 200);

and

TheMainMenu() function,

so use these things and your code will work for sure.

avatar image Guzaii · Sep 10, 2013 at 11:17 AM 0
Share

I think i got it fixed, i mixed the help from you with my own, and got this:

 var isPause = false;
 var MainMenu : Rect = Rect(10, 10, 200, 200);
  
 function Update () {
  if( Input.GetKeyDown(KeyCode.Escape))
    {
       isPause = !isPause;
       if(isPause)
          Time.timeScale = 0;
       else
          Time.timeScale = 1;
    }
 }
  
 function OnGUI()
 {
    if(isPause)
        GUI.Window(0, MainMenu, TheMainMenu, "Pause Menu");
 }
 
 function TheMainMenu () {
 if(GUILayout.Button("Main Menu")){
 Application.LoadLevel("MainMenu");
 }
 if(GUILayout.Button("Restart")){
 Application.LoadLevel("InGame");
 }
 if(GUILayout.Button("Quit")){
 Application.Quit();
 }
 }
avatar image DeveshPandey · Sep 10, 2013 at 11:30 AM 1
Share

You have to lock the mouse look by your own code, it will not locked by Time.timeScale, I was given you hint not full code.. lolz

Anyway its working now so you can hit accept answer and thumb up!!

Show more comments
avatar image

Answer by RyanZimmerman87 · Sep 08, 2013 at 03:34 AM

 //assign these publics in inspector once you attach script to empty object
 public GUIStyle GUIStyleButton;
 public Texture2D pauseButtonTexture;
 
 bool gamePausedBool;
 
 void Start()
 {
 gamePausedBool = false;
 Time.TimeScale = 1;
 }
 
 void OnGUI()
 {
 
 
 //player presses pause button while playing game
 //this script will need to be in the scene you can attach to some empty object.

if (gamePausedBool == false) {

 if (GUI.Button(new Rect(pauseVectorPosition.x, pauseVectorPosition.y, vectorSizeSmall.x, vectorSizeSmall.y), pauseButtonTexture, GUIStyleButton))
 {
 
 gamePausedBool = true;
 Time.timeScale = 0;
  
 }

return;

}

 else if (gamePausedBool == true)
 {
 //more buttons for all the paused game stuff..
 
 //button to unpause game...
 if (GUI.Button(new Rect(pauseVectorPosition.x, pauseVectorPosition.y, vectorSizeSmall.x, vectorSizeSmall.y), pauseButtonTexture, GUIStyleButton))
 {
 
 gamePausedBool = false;
 Time.timeScale = 1;
 
 }
 
 }
             
 }
 
 void Update()
 {
 if (gamePausedBool == true)
 {
 return;
 }
 
 //your normal game logic
 }

Sorry about format don't have time to try to fix atm.

Comment
RavenOfCode

People who like this

1 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 Guzaii · Sep 08, 2013 at 11:15 AM 0
Share

Thanks alot :) Now ill find out how to use it :)

avatar image Guzaii · Sep 10, 2013 at 10:41 AM 0
Share

What Unity version is this for? because i dont seem to get where to put it? (Im not running 4.2)

avatar image

Answer by sammy12345 · Dec 15, 2013 at 02:13 AM

How Do i Make It Soo I Can See my mouse ?

Comment

People who like this

0 Show 4 · 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 Guzaii · Dec 15, 2013 at 10:04 AM 0
Share

I don't use this script much anymore. But use Screen.showcursor .

And maybe my new script can help you:

 #pragma strict
  
 var paused : boolean;
 var myString : String = "Mute";
 var Mute : boolean;
 var guiSkin : GUISkin;
  
 function Start () {
  
 }
  
 function Update () {
  
     if(Input.GetKeyDown("escape")){
          paused = !paused;
        }
  
        if(paused)
          Time.timeScale = 0;
        else
          Time.timeScale = 1;
  
  
          if (Mute == true){     
        gameObject.GetComponent(AudioListener).enabled = false;   
     }
     else{
        gameObject.GetComponent(AudioListener).enabled = true;
     }
  
 }
  
 // JavaScript
 var icon : Texture2D;
  
 //var frameStyle : GUIStyle;
  
 function OnGUI () {
  
        GUI.skin = guiSkin;
  
     if(paused){
  
 //   GUI.Box (Rect (10,10, 100, 50), icon, frameStyle);
  
        if (GUI.Button (Rect (Screen.width/2 - 100,Screen.height/2 - 120, 200, 100), "Menu")) {
          Application.LoadLevel("Menu");
               Time.timeScale = 1;
        }
  
        if (GUI.Button (Rect (Screen.width/2 - 100,Screen.height/2,200,100), "Restart")) {
          Application.LoadLevel("Game");
               Time.timeScale = 1;
        }
  
        if (GUI.Button (Rect (Screen.width/2 - 100,Screen.height/2 + 120,200,100), myString)) {
          if (myString == "Mute"){
          myString = "Unmute";
          Mute = true;
          }
  
          else{
          myString = "Mute";
          Mute = false;
          }
        }
     }
 }


Hope this helps :-)

avatar image Guzaii · Dec 15, 2013 at 10:05 AM 0
Share

If you need more scripts, them I'm posting all my scripts on my forum: http://minacdev.com/forum

avatar image BMRX · Apr 21, 2015 at 06:21 PM 0
Share
 Cursor.visible = false;

Is how it's done now a days. :P

avatar image Guzaii · Apr 21, 2015 at 06:24 PM 0
Share

This was in 2013 :P i think i know by now ^^

avatar image

Answer by CelalQurbanov · Mar 30, 2014 at 03:17 PM

Don`t use Time.timescale = 0; Because if your any animation is playing your game will shoiw error(s) . Use :

Time.timeScale = 0.0001;

Comment

People who like this

0 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 Guzaii · Mar 30, 2014 at 04:29 PM 0
Share

Tine.scale = 0 Is working fine for me so far.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Multiple Cars not working 1 Answer

GUI problem 1 Answer

Full Screen Get smaller when i actived it 1 Answer

Pause Menu background problem 0 Answers

Gui placement help 1 Answer


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