Advertisement
johnnygoodguy2000

PauseMenu.cs

May 12th, 2024
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement; // Include this for SceneManager
  5.  
  6. public class PauseMenu : MonoBehaviour
  7. {
  8.     public string levelSelect; // Name of the level select scene
  9.     public string mainMenu; // Name of the main menu scene, corrected casing to camelCase
  10.  
  11.     public bool isPaused;// Variable to track if the game is paused
  12.     public GameObject pauseMenuCanvas;// Reference to the pause menu canvas object
  13.  
  14.     // Update is called once per frame
  15.     void Update()
  16.     {
  17.         if (Input.GetKeyDown(KeyCode.Escape))// Check if the escape key is pressed
  18.         {
  19.             isPaused = !isPaused;
  20.             Debug.Log("isPaused: " + isPaused);// Print the value of isPaused
  21.         }
  22.  
  23.         if (isPaused)
  24.         {
  25.             pauseMenuCanvas.SetActive(true);
  26.             Time.timeScale = 0f; // Pause the game
  27.             Debug.Log("isPaused: " + isPaused);// Print the value of isPaused
  28.         }
  29.         else
  30.         {
  31.             pauseMenuCanvas.SetActive(false);
  32.             Time.timeScale = 1f; // Resume game time
  33.             Debug.Log("game resumed "); // Print the value of isPaused
  34.         }
  35.     }
  36.  
  37.     public void Resume()// Function to resume the game
  38.     {
  39.         isPaused = false;// Set isPaused to false
  40.     }
  41.  
  42.     public void LevelSelect()
  43.     {
  44.         SceneManager.LoadScene(levelSelect); // Updated to use SceneManager
  45.     }
  46.  
  47.     public void Quit()
  48.     {
  49.         SceneManager.LoadScene(mainMenu); // Updated to use SceneManager
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement