campfire/Assets/Scripts/PauseMenu.cs
2020-04-20 00:12:50 +03:00

53 lines
1.4 KiB
C#

using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(CanvasGroup))]
public class PauseMenu : MonoBehaviour {
public GameState GameState;
public Options Options;
[Header("Option inputs")]
public Toggle InvertMouseY;
public Toggle CameraBobbing;
public Slider MouseSensitivity;
public Slider MasterVolume;
public Slider CampfireVolume;
public Slider AmbientVolume;
public Slider FootstepVolume;
private CanvasGroup Canvas;
private bool Paused {
get {
return GameState.Current == State.Paused;
}
}
private void Awake() {
Canvas = GetComponent<CanvasGroup>();
Fade(true);
}
private void Start() {
InvertMouseY.isOn = Options.InvertMouseY;
CameraBobbing.isOn = Options.CameraBobbing;
MouseSensitivity.value = Options.MouseSensitivity;
MasterVolume.value = Options.MasterVolume;
CampfireVolume.value = Options.CampfireVolume;
AmbientVolume.value = Options.AmbientVolume;
FootstepVolume.value = Options.FootstepVolume;
}
private void Update() {
Fade(false);
}
private void Fade(bool instant) {
Canvas.alpha = Mathf.Lerp(Canvas.alpha, Paused ? 1 : 0, instant ? 1 : 10f * Time.unscaledDeltaTime);
Canvas.blocksRaycasts = Paused;
}
public void Resume() {
GameState.Current = State.Playing;
}
}