- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using TMPro;
- public class PauseMenuBehaviour : MonoBehaviour
- {
- float timeScale;
- [SerializeField] private Texture2D cursorTexture;
- private Vector2 cursorHotspot;
-
- public static bool isPaused { get; private set; } = false;
- public GameObject menu;
- private void Start()
- {
- Cursor.visible = false;
- cursorHotspot = Vector2.zero;
- Cursor.SetCursor(cursorTexture, cursorHotspot, CursorMode.ForceSoftware);
- isPaused = false;
- if (menu != null)
- {
- isPaused = menu.activeSelf;
- }
- Cursor.lockState = CursorLockMode.Locked;
- }
- public void Resume()
- {
- if (isPaused)
- {
- Time.timeScale = timeScale;
- isPaused = false;
- Cursor.visible = false;
- Cursor.lockState = CursorLockMode.Locked;
- }
- }
- public void Pause()
- {
- if (!isPaused) {
- timeScale = Time.timeScale;
- Time.timeScale = 0;
- isPaused = true;
- Cursor.visible = true;
- Cursor.lockState = CursorLockMode.None;
- }
- }
- public void ReturnToMainMenu()
- {
- Resume();
- Cursor.lockState = CursorLockMode.None;
- SceneManager.LoadScene(1);
- }
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- if (isPaused)
- {
- Resume();
-
- }
- else
- {
- Pause();
- }
-
- }
- if (menu != null)
- {
- menu.SetActive(isPaused);
- }
- }
-
- public void ButtonOverlay(TMP_Text buttontext)
- {
- buttontext.color = new Color32(255, 212, 73, 255);
- }
- public void ButtonExitOverlay(TMP_Text buttontext)
- {
- buttontext.color = Color.black;
- }
- }