- Home /
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");
}
}
Why are you calling Application.Quit() before loading a scene? Application.Quit() attempts to quit the application...
good Eye i missed that that could deff be it
it is so the scene(game) will quit and load the new scene(menu) otherwise it wont quit the game
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.
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...
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.
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.
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.
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.