Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement; // Include this for SceneManager
- public class PauseMenu : MonoBehaviour
- {
- public string levelSelect; // Name of the level select scene
- public string mainMenu; // Name of the main menu scene, corrected casing to camelCase
- public bool isPaused;// Variable to track if the game is paused
- public GameObject pauseMenuCanvas;// Reference to the pause menu canvas object
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Escape))// Check if the escape key is pressed
- {
- isPaused = !isPaused;
- Debug.Log("isPaused: " + isPaused);// Print the value of isPaused
- }
- if (isPaused)
- {
- pauseMenuCanvas.SetActive(true);
- Time.timeScale = 0f; // Pause the game
- Debug.Log("isPaused: " + isPaused);// Print the value of isPaused
- }
- else
- {
- pauseMenuCanvas.SetActive(false);
- Time.timeScale = 1f; // Resume game time
- Debug.Log("game resumed "); // Print the value of isPaused
- }
- }
- public void Resume()// Function to resume the game
- {
- isPaused = false;// Set isPaused to false
- }
- public void LevelSelect()
- {
- SceneManager.LoadScene(levelSelect); // Updated to use SceneManager
- }
- public void Quit()
- {
- SceneManager.LoadScene(mainMenu); // Updated to use SceneManager
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement