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 the FixedUpdate function:
/// <summary>
/// FixedUpdate is called at a fixed framerate and is a prime place
/// to put
/// Anything based on 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 FixedUpdate function...
The added code makes it so that if the game is paused, we will not do anything within the function.
- We then also need to add the same script to the top of the Update function as well:
/// <summary>
/// Update is called once per frame
/// </summary>
private void Update()
{
// If the game is paused, don...