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?
Hi silo, For game pause action here some steps please follow these steps.
public GameObject PopUp;
- First make one pop up window with Resume or Restart buttons(Gui Textures)
- In Start() false that window. Ex = PopUp.SetActive(False);
- On Pause Click true that window Ex = PopUp.SetActive(true);
- 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.
- On click Resume just disable popup and resume your game window and on restart just reload your game.