-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameUI.cs
More file actions
38 lines (32 loc) · 683 Bytes
/
GameUI.cs
File metadata and controls
38 lines (32 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class GameUI : MonoBehaviour
{
public Image fadePlane;
public GameObject gameOverUI;
void Start () {
FindObjectOfType<Player>().OnDeath += OnGameOver;
}
void OnGameOver()
{
StartCoroutine(Fade(Color.clear, Color.black, 1));
gameOverUI.SetActive(true);
}
IEnumerator Fade(Color from, Color to, float time)
{
var speed = 1 / time;
var percent = 0f;
while (percent < 1)
{
percent += Time.deltaTime * speed;
fadePlane.color = Color.Lerp(from, to, percent);
yield return null;
}
}
// UI Input
public void StartNewGame()
{
Application.LoadLevel("Game");
}
}