Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by ahamelin9 · Feb 20, 2019 at 03:09 PM · unityeditorprogrammingpause menu

Pause menu not working???

When ever i am using the pause menu it wont let me use anything after clicking something other than the remume button (that one works) but when i hit options or the main menu button unity thinks it is paused again forcing me to hit escape again but then it thinks it is paused and resumed at the same time...,,I have the game paused and everything works just fine but as soon as I click an action liek the options menu or the quit button they both think the game is paused. The resume button works just fine but thats because im resuming the game but when i hit options i cant click anything and same with the main menu...

here is the code that i used

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Pause : MonoBehaviour {

 //public static bool GameIsPaused = false;
 static bool GameIsPaused = false;

 public GameObject pauseMenuUI;
 
 // Update is called once per frame
 void Update () {
     if(Input.GetKeyDown(KeyCode.Escape))
         {
         if (GameIsPaused)
         {
             Resume();
         }
         else
         {
             DoPause();
         }
     }
 }

 public void Resume ()
 {
     pauseMenuUI.SetActive(false);
     Time.timeScale = 1f;
     GameIsPaused = false;
 }

 void DoPause ()
 {
     pauseMenuUI.SetActive(true);
     Time.timeScale = 0.0f;
     GameIsPaused = true;
 }

 public void LoadMenu()
 {
     pauseMenuUI.SetActive(false);
     GameIsPaused = false;
     Time.timeScale = 1f;
     Application.Quit();
     SceneManager.LoadScene("menu");
 }

}

Comment
Add comment · Show 4
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 RobAnthem · Feb 20, 2019 at 03:15 PM 0
Share

Why are you calling Application.Quit() before loading a scene? Application.Quit() attempts to quit the application...

avatar image zereda-games RobAnthem · Feb 20, 2019 at 03:31 PM 0
Share

good Eye i missed that that could deff be it

avatar image ahamelin9 RobAnthem · Feb 25, 2019 at 03:21 PM 0
Share

it is so the scene(game) will quit and load the new scene(menu) otherwise it wont quit the game

avatar image zereda-games · Feb 20, 2019 at 03:29 PM 0
Share

I gotta look at my own for a $$anonymous$$ Brb.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nocktion · Feb 20, 2019 at 03:23 PM

Don't use Time.timeScale for pausing the game. Time scale is used by a lot of things including coroutines and therefore setting it to 0f can make a lot of things stop working. In you place I would use GameIsPaused public and use it to check if for example the player can be updated.

Comment
Add comment · Show 6 · 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 zereda-games · Feb 20, 2019 at 03:28 PM 0
Share

FYI, Time.timeScale* i had a spelling error is used if you wanna pause the players actions, which is what he wants to do.

Update and to why i say this: so Time.timeScale=0 paused and Time.timeScale=1 unpaused it the right method. @RobAnthem ·spotted the Application.Quit(); This quits a game and closes application when build but doesn't have an effect visually in the editor.. it could cause things like a pause to not unpause because it would simulate that the player has "quit the application", but the editor in a way can be like a online server that is offline in reality. Why i say this is...: If using LAN setup setting in the editor and linking two Unity's PC's together, if the editor of PC 1 - "host" also is constant once enabled, and even when host PC player it in pause or stop mode

If the instance of server emulation is stopped neither can connect in a multiplayer environment, but once hosting is enabled on one PCof the two PC's, another can be a "user B" and "user a" is the host PC player from my understanding, also when there is two PC's who hit play and link , if one player paused the other would not. I don't know if that is too confusing, or if i explained that well all enough, but it is a necessary thing in a multiplayer environment to avoid pausing the whole world and all the players in it...

avatar image Nocktion · Feb 20, 2019 at 03:46 PM 0
Share

But Time.timeScale stops everything not just the player

avatar image zereda-games Nocktion · Feb 20, 2019 at 04:43 PM 0
Share

not with my experience, ive had things moving in the background of my games while paused. but my player rig or anything, couln't move.

avatar image RobAnthem Nocktion · Feb 20, 2019 at 04:51 PM 1
Share

ACTUALLY Time.timeScale = 0 simply sets the scale of "referenced" time to zero, frames still run like normal but all functions that use Time.anything will return a time value of zero. This appears to pause things because every action we see is usually based on Time.deltaTime or Time.fixedDeltaTime, Time.smoothDeltaTime etc. So button clicks still work, audio still plays, things are technically still happening.

avatar image zereda-games RobAnthem · Feb 20, 2019 at 05:02 PM 0
Share

that's a better way of putting it then what i have it. and how i understand it as well.. couldn't put it into words i guess.

avatar image ahamelin9 · Feb 25, 2019 at 03:15 PM 0
Share

Not to sure how i would go into making GameIsPaused public. I tried to change it into a public static bool but seems to do the same thing.

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

111 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 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 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 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 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

Pause System not working :/ 2 Answers

How do I get Unity to report "You have 1 bullet remaining" instead of "You have 1 bullets remaining"? 2 Answers

Controller work differently with same code and objects, but in different position 1 Answer

I need help with registering blocks in my 3d tetris game.,trying to make a 3d tetris and need help registering subBlocks? 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