45 lines
998 B
C#
45 lines
998 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
public class GameManager : MonoBehaviour {
|
|
[SerializeField] public float Timescale = 1;
|
|
private float PrevTimescale = 1;
|
|
[SerializeField] private GameObject CrystalRef;
|
|
public static GameObject Crystal;
|
|
|
|
public static bool IsPaused { get; private set; }
|
|
[SerializeField] private GameObject pauseMenuUI;
|
|
|
|
private void Awake() {
|
|
Crystal = CrystalRef;
|
|
}
|
|
|
|
|
|
void Update() {
|
|
if (Input.GetKeyDown(KeyCode.Escape))
|
|
TogglePause();
|
|
SetTimeScale();
|
|
}
|
|
|
|
public void TogglePause() {
|
|
IsPaused = !IsPaused;
|
|
Time.timeScale = IsPaused ? 0f : 1f;
|
|
AudioListener.pause = IsPaused;
|
|
pauseMenuUI?.SetActive(IsPaused);
|
|
}
|
|
|
|
public void SetTimeScale() {
|
|
if (IsPaused) return;
|
|
|
|
if (PrevTimescale != Timescale) {
|
|
Time.timeScale = Timescale;
|
|
PrevTimescale = Timescale;
|
|
}
|
|
}
|
|
}
|