Blog 5 – Week 10

Pause, Wait a Minute

Good evening, another week has passed and next week is the final version of our game. This week I worked on the pause menu along with some more sound implementation and cleaning up the main menu a bit. Though this post will focus on the pause menu and how I went about making it work. I approached this week knowing that I wanted to implement the pause menu which would display a “Restart” button, “Menu” button and a “Quit” button. Creating this menu was just like creating the main menu. I ran into a problem though approaching this like that because once you load into a new scene, it would then have to reload the level scene (all the way from the beginning). This was not ideal as it proved to me and required a lot of processing power since it would load, unload and then load the level all again. I tried fixing this by having the pause scene just turn off, but then it left you with a blank canvas still within the pause scene just the objects would not be there.

horriblePause
The level is not loaded in the background, this is it’s own scene which was very bad.

So, to fix this problem I decided to put the same things you would have for a GUI into the level scene. This involved the canvas and panel that went along with the GUI. Within this you would have the buttons on the panel and the correct sprites and text assigned. Getting the buttons to work was pretty simple since I had done this once before. I added a Vertical Layout Group to the panel object and that made all the buttons uniform and even across the canvas. Then within each of the buttons I had events for the OnClick() which involved deactivating the canvas when you clicked on the resume button, loading the menu scene when you clicked on the menu button, and quitting the game when you clicked on the quit button. Since having this panel and canvas in the level scene, deactivating the pause menu made the pause menu disappear from screen but not have to reload the whole level scene. To physically stop time in the game I had to do some research and the line Time.timeScale made all this happen. If it was equal to 1, time was continueing forward in the game, if it was equal to 0, time stopped. So, if the pause menu was active, time was 0 and if resume was pressed then time went to 1.

ButtonScript
The button script that comes with Unity makes things much easier and the On Click() helped out a bit too.
GUICanvas
This is what is included to make the pause menu look like a menu not a part of the game.

Author: Kyle Alley

Game Design and Programming

Leave a comment