campfire/Assets/Scripts/GameOverMenu.cs

33 lines
833 B
C#
Raw Normal View History

2020-04-19 20:04:45 +02:00
using UnityEngine;
using UnityEngine.SceneManagement;
2020-04-19 02:32:20 +02:00
[RequireComponent(typeof(CanvasGroup))]
public class GameOverMenu : MonoBehaviour {
public GameState GameState;
private CanvasGroup Canvas;
private void Awake() {
Canvas = GetComponent<CanvasGroup>();
UpdateCanvas(true);
}
private void Update() {
UpdateCanvas(false);
}
private void UpdateCanvas(bool instantTransition) {
bool IsGameOver = GameState.Current == State.GameOver;
2020-04-19 03:02:40 +02:00
Canvas.alpha = Mathf.Lerp(Canvas.alpha, IsGameOver ? 1 : 0, instantTransition ? 1 : 2f * Time.deltaTime);
2020-04-19 20:04:45 +02:00
Canvas.blocksRaycasts = IsGameOver;
}
public void Replay() {
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void Exit() {
Application.Quit();
2020-04-19 02:32:20 +02:00
}
}