PauseManager.cs
using UnityEngine; public class PauseManager : MonoBehaviour { bool isPaused = false; public GameObject PauseMenu; float timeScale; void Update() { if(Input.GetKeyDown(KeyCode.Escape)) { if(isPaused) Resume(); else Pause(); } } void Pause() { isPaused = true; PauseMenu.SetActive(true); timeScale = Time.timeScale; Time.timeScale = 0.0f; } void Resume() { isPaused = false; PauseMenu.SetActive(false); Time.timeScale = timeScale; } }
GameManager.cs
using System.Collections; using UnityEngine; public class GameManager : MonoBehaviour { void Start() { StartCoroutine(DebugCoroutine()); } void Update() { if (Time.timeScale == 0) return; Debug.Log("Update is running..."); } void FixedUpdate() { Debug.Log("FixedUpdate is running..."); } IEnumerator DebugCoroutine() { while(true) { yield return new WaitWhile(() => Time.timeScale == 0); yield return new WaitForEndOfFrame(); Debug.Log("coroutine is running..."); } } }