using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using Assets.Scripts.CharacterScripts; public class PauseMenuController : MonoBehaviour{ public TextMeshProUGUI stats; // The text for the player's stats in the pause menu public GameObject pauseMenu; // Reference to the overall pause menu canvas private bool isPaused = false; // Variable to see if we're currently paused or not public PlayerController player; // Reference to the player void Start(){ // Make sure the pause menu is assigned to the canvas if (pauseMenu != null){ // If the pause menu is initialized, set it's active status to false (makes it disappear) pauseMenu.SetActive(false); } // Initialize the player reference player = GameObject.FindGameObjectWithTag("Player").GetComponent(); } void Update(){ // Press "P" to pause the game if (Input.GetKeyDown(KeyCode.P)){ // Toggle the pause menu TogglePauseMenu(); } // For some reason, the stats would only update after the succeeding level (ex: level 2 would reflect after leveling to 3) // So just update every frame to ensure accuracy as well stats.text = "STATS:\n" + "MAX HP: " + player.maxHealth + "\nATTACK: " + player.playerDamage + "\nDEFENSE: " + player.playerDefense; } void TogglePauseMenu(){ if (pauseMenu != null){ // Set our boolean to true because we're paused isPaused = true; // Activate the pause menu pauseMenu.SetActive(isPaused); // Freeze the game while pause menu is active Time.timeScale = 0f; } } // For clicking the Resume button public void ResumeGame(){ // Resume the game and hide the pause menu isPaused = false; pauseMenu.SetActive(false); Time.timeScale = 1f; // Unfreeze gameplay } // For clicking the exit button public void ExitGame(){ // Quit the application Application.Quit(); } public void UpdateStats(){ // Update the player's stats in the pause menu stats.text = "STATS:\n" + "MAX HP: " + player.maxHealth + "\nATTACK: " + player.playerDamage + "\nDEFENSE: " + player.playerDefense; } }