Skip to content

Commit

Permalink
fix being able to pause in the gameover screen
Browse files Browse the repository at this point in the history
  • Loading branch information
user5522 committed Jan 2, 2025
1 parent a3b5dee commit 36e006f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class GameManager : MonoBehaviour

public UnitHealth playerHealth = new UnitHealth(100, 100);

public bool isGameOver;
public bool isPaused;

bool waiting;
float previousTimescale;

Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/GameOverScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class GameOverScreen : MonoBehaviour

void Start()
{
GameManager.Instance.isGameOver = true;
player.SetActive(false);
StartCoroutine(FlashText());
Time.timeScale = 1;
Expand All @@ -21,6 +22,7 @@ void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
GameManager.Instance.isGameOver = false;
gameObject.SetActive(false);
player.SetActive(true);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
Expand Down
10 changes: 4 additions & 6 deletions Assets/Scripts/Pause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ public class Pause : MonoBehaviour

private float previousTimeScale;

public static bool isPaused = false;

void Start() => previousTimeScale = Time.timeScale;

void Update()
Expand All @@ -17,22 +15,22 @@ void Update()

public void TogglePause()
{
if (Time.timeScale > 0)
if (Time.timeScale > 0 && !GameManager.Instance.isGameOver)
{
previousTimeScale = Time.timeScale;
Time.timeScale = 0;
AudioListener.pause = true; // for audio whenever that gets added
pauseMenu.SetActive(true);

isPaused = true;
GameManager.Instance.isPaused = true;
}
else if (Time.timeScale == 0)
else if (Time.timeScale == 0 && !GameManager.Instance.isGameOver)
{
Time.timeScale = previousTimeScale;
AudioListener.pause = false; // for audio whenever that gets added
pauseMenu.SetActive(false);

isPaused = false;
GameManager.Instance.isPaused = false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/SettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void LoadSettings()

private void UpdateCursorVisibility()
{
Cursor.visible = Pause.isPaused;
Cursor.lockState = Pause.isPaused ? CursorLockMode.None : CursorLockMode.Locked;
Cursor.visible = GameManager.Instance.isPaused;
Cursor.lockState = GameManager.Instance.isPaused ? CursorLockMode.None : CursorLockMode.Locked;
}
}
8 changes: 4 additions & 4 deletions Assets/Scripts/SlowDownTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ void Start()

void Update()
{
if (Input.GetKeyDown(KeyCode.Tab) && !Pause.isPaused) ToggleSlowMotion();
if (isSlowMotion && !Pause.isPaused)
if (Input.GetKeyDown(KeyCode.Tab) && !GameManager.Instance.isPaused) ToggleSlowMotion();
if (isSlowMotion && !GameManager.Instance.isPaused)
{
availableSlowdownTime -= Time.unscaledDeltaTime;
if (availableSlowdownTime <= 0) ToggleSlowMotion();
}
else if (!Pause.isPaused) RechargeSlowdownTime();
else if (!GameManager.Instance.isPaused) RechargeSlowdownTime();
UpdateUI();
HandleGamePaused();
}
Expand Down Expand Up @@ -96,7 +96,7 @@ void SetDimming(bool enabled)

void HandleGamePaused()
{
if (Pause.isPaused && isSlowMotion) Time.timeScale = 0f;
if (GameManager.Instance.isPaused && isSlowMotion) Time.timeScale = 0f;
}

void UpdateUI() => bar.fillAmount = availableSlowdownTime / maxSlowdownTime;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/WeaponController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WeaponController : MonoBehaviour

void Update()
{
if (Pause.isPaused) return;
if (GameManager.Instance.isPaused) return;

if (Input.GetMouseButtonDown(0))
{
Expand Down

0 comments on commit 36e006f

Please sign in to comment.