To create a pause menu I used another tutorial from the Brackeys YouTube channel (https://www.youtube.com/watch?v=JivuXdrIHK0&t=62s).
The first thing to set up was a canvas for the pause menu. Then fill this with UI elements. The three choices I wanted to give the player were to resume the game, adjust the options, or exit to the menu. These were all created with buttons.
I needed to create a script similar to the options menu in order for the UI to work with the game. Here is the script:
I had to create a bool to see whether the game was paused, and if the game was, then the timescale needed to be set to zero (pause time of the game). I then created two functions, one for pausing the game and one for resuming. As well as adjusting the timescale, these functions both set the pause menu UI to active in disabled where needed. I then linked up the functions with the correct buttons. For the options button, I simply copied what I had done with the main menu, where the canvas would be enabled/disabled based on the pressed button, as shown here:
After this there was not much more to do, other than test that it worked, which it did.
As stated earlier in the blog, this will not be a function in the second level. That level will not enable you to pause the game as it makes the game a little more difficult for the player.
Comments
Post a Comment