This week my team broke off into more specific tasks where there wouldn’t be too much overlap with what we were each implementing. Someone chose to design and implement the screens for when the game ends, another person chose to fix up some loose ends in the main game, and I chose to implement the main opening menu, along with a pause menu for when the game is actually running.
I’ve been following along with a Unity tutorial for a few weeks now, and just last week the tutorial covered the basics of pausing a game. Of course, after watching this and taking notes I thought I’d be able to implement pausing functionality within my own project’s game in just a few minutes. However, just like with a lot of other coding concepts, actually implementing this took way longer than I had originally anticipated.
I finished the main opening menu screen within a few hours, and the part that took the longest with that was trying to find a fitting, free font style for the title. Then I was able to design the in-game pause menu by using a few canvas panels and buttons. I wrote the first scripts, and (just like how the tutorial did it) I created animations and an animator controller for the menu.
However, when I started testing the game in the Unity editor, our paddle (our game is a remake of Atari’s breakout) would still move around. And the buttons had no functionality. So began a three day long rabbit hole into getting the pause menu to actually work.
At first, I was trying to pause the game within our GameManager. Here I was reducing the time scale to 0, which is supposed to halt all of the physics within the engine. Though, I falsely believed that this was leading to my buttons also getting halted. And I still had to deal with the moving paddle, which completely ignored the absence of a time scale.
I then tried to not use any time scale mechanics to pause the game, and instead created checks within the update functions for everything that moved within the game. I created a new Pause class with one public member variable, a boolean to tell whether or not the Pause was active. Within the update methods for the ball and paddle, I did a check to the Pause class to see if it’s active member variable was set to True.
I was successful with finally getting the Paddle to stop moving with this technique … however, the ball decided that it was just going to ignore this check, and kept moving when the pause was active.
After another day of experimenting with this, I finally combined these two techniques. Inside the Pause class, if its only member variable is true, then the time scale reduces to 0. On top of this, I kept the check inside the Paddle’s update function.
With this I finally, got both the ball and paddle to stop moving when the game was Paused. And I got the menu to toggle with the ESC key. However, even after all this, my buttons still wouldn’t work.
After watching a few more tutorials. I realized I still needed an Event System in order for the UI to work properly. With that, I linked the buttons up to their parent’s methods, and finally got everything within the pause menu to work.
That just goes to show that even the things that we think are going to be simple to implement can end up taking days or even longer to get working properly. Who would’ve known that pausing a game would be so hard.
Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from Gravatar.