-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameManager.cs
62 lines (57 loc) · 1.57 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
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public int enemiesAlive = 0;
public int enemiesKilled = 0;
public int round = 3;
public GameObject[] spawnPoints;
public GameObject enemyPrefab;
public GameObject endScreen;
public AudioSource background;
public Text enemies;
// Start is called before the first frame update
void Start()
{
background.Play(0);
}
// Update is called once per frame
void Update()
{
if (enemiesAlive == 1)
{
round++;
NextWave(round);
}
enemies.text = "Killed: " + enemiesKilled.ToString();
}
public void NextWave(int round)
{
for (int i = 0; i < round; i++)
{
GameObject spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)];
GameObject enemySpawned = Instantiate(enemyPrefab, spawnPoint.transform.position, Quaternion.identity);
enemySpawned.GetComponent<EnemyController>().gameManager = GetComponent<GameManager>();
enemiesAlive++;
}
}
public void EndGame()
{
endScreen.SetActive(true);
background.Pause();
}
public void Restart()
{
Time.timeScale = 1;
SceneManager.LoadScene(0);
background.Play();
}
public void Quit()
{
Application.Quit();
}
}