My Pause Script does not unpause.

I am new to Unity and am trying to create a pause menu. When the game object is active, the game does pause as I had wanted. However, the game is still paused when the game object is set to not active again. Here is the script which I have now:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseMenu : MonoBehaviour
{
    void Update()
    {
        if (gameObject.activeSelf)
        {
            Time.timeScale = 0f;
        }
        else
        {
            Time.timeScale = 1f;
        }
    }
}

The Update method does not run when the object is not active. So you could remove the if block and reduce your Update method to only line 11, and it would be exactly equivalent.

You probably want to use the OnEnable and OnDisable methods instead.

1 Like