Tweaking - Adding a “Pause” menu

Have to go afk? Pause the game then!

Timo Schmid
Nerd For Tech
2 min readMay 13, 2021

--

We all know this kind of situation: Your mid-game but all of a sudden our phone rings and you have to answer the call. Or, what might be more common, you have to go to the toilet. And if I have to take a guess here, you will pause the game in such a situation - if you’re not playing an online game I mean. Let’s implement such a feature in the Space Shooter as well to get you covered in such situations!

To manipulate how fast things are happening during gameplay, Unity has a method called Time.timeScale.

Let’s take a look at what exactly want to do with pseudocode:

We just need to add four little things here:

  • A bool variable to check if the game is paused or not
  • A method to trigger the Pause functionality
  • A method to continue the game
  • A method to check for the button presses and call the other methods then

For the variable, I just named it _isGamePaused.

For points two and three, I created a new method to take care of the individual tasks inside the UIManager.cs script. And as text elements for the Pause system should only be visible when the game is paused, I added a reference to them as well and enabled and disabled them accordingly.

For the last task, I created another method inside the GameManager.cs script.

Don’t forget to set the bool to true when the game gets paused!

To make that work, make sure to call the method inside void Update() as well. Otherwise, the pausing system will not work at all because it will not checked whether the C key has been pressed or not.

This is how it looks like inside the game:

And that’s about it for todays post. If you ever have to go away from your keyboard and don’t want the game continue to run, you can now do that.

--

--

Timo Schmid
Nerd For Tech

The mission? Becoming a game developer! RPG is the dream! Writing down my journey here for me and for everyone interested. Thanks for showing interest :)