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 silo28 · May 05, 2014 at 07:02 AM · pause menu

How do I design a pause function?

I'm new to Unity, I'm trying to create a game which requires a pause function.The Pause should work as; when player click the pause button the game should stop its function and a window/image should pop up with 2 options, main menu and resume. If the player click main menu the main menu scene should appear, if resume the pop up window should disappear and the game should continue in the same scene. How do I have to write the script for that?

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 fafase · May 05, 2014 at 07:05 AM 1
Share

Put down your words into a more appropriate situation:

  1. if(pause key is press) enable pause, stop game

  2. if (pause enabled)show gui, drawing 2 buttons

  3. if(GUI button for resume is pressed) disable pause, restart game

  4. if(GUI button for main menu pressed) disable pause, restart game, load menu

This is pretty much a pseudo code of your Pause script.

Also, I am pretty sure there are already a few answers on this topic.

avatar image silo28 · May 06, 2014 at 09:21 AM 0
Share

Thank you for the help, I used the below code but it doesn't work as I wish. the problem is before I press pause button the GUI window appears, what is wrong with this code?

pragma strict

var isPause = false; var $$anonymous$$ain$$anonymous$$enu : Rect = Rect(10, 10, 200, 200); var WinTexture : Texture; function Update () { if( Input.Get$$anonymous$$ouseButton(1)) { isPause = !isPause; if(isPause) Time.timeScale = 0; else Time.timeScale = 1; } }

 function OnGUI()
 {
 GUI.Button (new Rect (230, 540, 100, 50), "Pause");
 isPause = !isPause;
 if(isPause)
 GUI.Window(0, $$anonymous$$ain$$anonymous$$enu, The$$anonymous$$ain$$anonymous$$enu, WinTexture);
 }
 
 function The$$anonymous$$ain$$anonymous$$enu () {
 if(GUILayout.Button("$$anonymous$$ain $$anonymous$$enu")){
 Application.LoadLevel("$$anonymous$$ain$$anonymous$$enu");
 }
 if(GUILayout.Button("Restart")){
 Application.LoadLevel("GamePlay");
 }
 }
avatar image AlucardJay silo28 · May 06, 2014 at 09:24 AM 1
Share

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. At Unity Answers, Answer means Solution, not Response.

Please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by VIPINSIRWANI · May 05, 2014 at 07:20 AM

Hi silo, For game pause action here some steps please follow these steps.

 public GameObject PopUp; 

  1. First make one pop up window with Resume or Restart buttons(Gui Textures)

  2. In Start() false that window. Ex = PopUp.SetActive(False);

  3. On Pause Click true that window Ex = PopUp.SetActive(true);

  4. For Game Functionality pause you can use Time.timeScale = 0 for pause and time.TimeScale = 1 for game resume but this is not good practice to play with frames call so instead of that thing you can use some boolean value for Pause and Resume.

  5. On click Resume just disable popup and resume your game window and on restart just reload your game.

Comment
Add comment · 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

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

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

Related Questions

GUI Menu Esc Button to Show and Hide it? 2 Answers

Another problems about Pause Menu 1 Answer

C# problem with pause menu 2 Answers

Camera Keeps Following Mouse in Pause Menu 0 Answers

When I pause during the countdown the game does not freeze PLS SOMEONE HELP. 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