campfire/Assets/Scripts/PauseMenu.cs

23 lines
608 B
C#
Raw Normal View History

2020-04-18 18:26:35 +02:00
using UnityEngine;
[RequireComponent(typeof(CanvasGroup))]
public class PauseMenu : MonoBehaviour {
public bool Paused = false;
private CanvasGroup Canvas;
private void Awake() {
Canvas = GetComponent<CanvasGroup>();
2020-04-18 22:52:37 +02:00
Canvas.alpha = Paused ? 1 : 0;
2020-04-18 18:26:35 +02:00
}
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);
}
}