-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameManager.cs
72 lines (56 loc) · 1.56 KB
/
GameManager.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameManager : MonoBehaviour {
[SerializeField]
GameObject gameOverScreen;
[SerializeField]
Text killsText;
[SerializeField]
Text timeText;
[SerializeField]
GameObject gameWonScreen;
[SerializeField]
Text winKillsText;
[SerializeField]
Text winTimeText;
public int kills = 0;
float startTime;
void Awake()
{
startTime = Time.time;
Time.timeScale = 1f;
}
public void GameOver()
{
int timePlayed = Mathf.RoundToInt(Time.time - startTime);
if (timePlayed < 60)
timeText.text = "Time Played: " + timePlayed + " Seconds";
else
timeText.text = "Time Played: " + timePlayed / 60 + " Minutes";
killsText.text = "Enemies Killed: " + kills;
gameOverScreen.SetActive(true);
Time.timeScale = 0f;
print ("Game over");
}
public void GameWon()
{
int timePlayed = Mathf.RoundToInt(Time.time - startTime);
if (timePlayed < 60)
winTimeText.text = "Time Played: " + timePlayed + " Seconds";
else
winTimeText.text = "Time Played: " + timePlayed / 60 + " Minutes";
winKillsText.text = "Enemies Killed: " + kills;
gameWonScreen.SetActive(true);
Time.timeScale = 0f;
print("Game won");
}
public void Restart()
{
SceneManager.LoadScene("Main");
}
public void GoToMenu()
{
SceneManager.LoadScene("Menu");
}
}