campfire/Assets/Scripts/PauseMenu.cs

23 lines
608 B
C#

using UnityEngine;
[RequireComponent(typeof(CanvasGroup))]
public class PauseMenu : MonoBehaviour {
public bool Paused = false;
private CanvasGroup Canvas;
private void Awake() {
Canvas = GetComponent<CanvasGroup>();
Canvas.alpha = Paused ? 1 : 0;
}
private void Update() {
if (Input.GetKeyDown(KeyCode.Escape)) {
Paused = !Paused;
}
Time.timeScale = Mathf.Lerp(Time.timeScale, Paused ? 0 : 1, 10f * Time.unscaledDeltaTime);
Canvas.alpha = Mathf.Lerp(Canvas.alpha, Paused ? 1 : 0, 10f * Time.unscaledDeltaTime);
}
}