Pausing the game
To get the game to pause correctly, we will tweak some scripts we’ve written previously using the following steps:
- Open the
PlayerBehaviour
script and add the code highlighted in bold to theFixedUpdate
function:/// <summary> /// FixedUpdate is a prime place to put physics /// calculations happening over a period of time. /// </summary> void FixedUpdate() { /* If the game is paused, don't do anything */ if (PauseScreenBehaviour.paused) { return; } // Check if we're moving to the side var horizontalSpeed = Input.GetAxis("Horizontal") * dodgeSpeed; // Rest of the FixedUpdate function...
The added code makes it so that if the game is paused, we will not do...