Files
JourneyToNowhere_Unity/Assets/Scripts/SingleUtils/PausePanel.cs
T

51 lines
1.3 KiB
C#
Raw Normal View History

2024-01-27 08:49:55 +08:00
using JTN;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PausePanel : MonoBehaviour
{
public GameObject PauseMenuPanel;
public GameObject PauseButton;
public KeyCode PauseKey = KeyCode.Escape;
public bool Paused;
public FirstPersonController PlayerController;
void Update()
{
if (PauseMenuPanel && PauseButton)
{
if (Input.GetKeyDown(PauseKey))
{
Debug.Log("Paused with " + PauseKey.ToString());
Pause();
}
}
}
public void Pause()
{
Debug.Log("Pause state: " + Paused);
if (!Paused)
{
PlayerController.enabled = false;
PauseButton.SetActive(false);
PauseMenuPanel.SetActive(true);
Paused = true;
Cursor.lockState = CursorLockMode.None;
Time.timeScale = 0;
}
else
{
PlayerController.enabled = true;
PauseButton.SetActive(true);
PauseMenuPanel.SetActive(false);
Paused = false;
Cursor.lockState = CursorLockMode.Locked;
Time.timeScale = 1;
}
}
}