Pausing a game
I've made an in game menu, so when I click on my menu button my menu pops up with a "Back" button, "Instructions" button and a "Main Menu" button that takes you to another menu on it's own scene. Whilst in my menu the game still plays, I've looked on YouTube but the ones shown on there won't work for me? Also, in game I can only go onto the menu and then go back in to the game once but it won't work the second time on the same level? I want it so I can click the menu button any time on the same level and it takes me to my menu. Thanks
Answer by Zoedingl · Jun 22, 2020 at 11:23 AM
Maybe you can create the pause screen just as a panel over the whole screen in the same scene as the game. To pause the game, simply write this:
Time.timeScale = 0f;
To resume the game, just write this:
Time.timeScale = 1f;
Hope this helped.
Answer by wah2068 · Jun 22, 2020 at 01:59 PM
Thanks, here's my menu script,
using UnityEngine; using UnityEngine.SceneManagement; using System.Collections; using System.Collections.Generic; using System.Threading;
public class MainMenu : MonoBehaviour { public void mainMenu() { SceneManager.LoadScene(0); }
public void playGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void continueGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void QuitGame()
{
Debug.Log("Quit!");
Application.Quit();
}
} So with this script I go to the On Click in the inspector window and use the parts of the script needed for each of the things I have in the menu. I don't know where to put the Time.timeScale in there? Thanks for the reply
Your answer
Follow this Question
Related Questions
Pause Menu 1 Answer
problem with timeScale = 0 (game paused) 0 Answers
Mouse dont move in pausemenu,Can move with mouse in pause menu 0 Answers
Highlight Button not working 1 Answer