-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameMaster.cs
More file actions
90 lines (72 loc) · 2.24 KB
/
Copy pathGameMaster.cs
File metadata and controls
90 lines (72 loc) · 2.24 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using UnityEngine;
using System.Collections;
public class GameMaster : MonoBehaviour {
public static GameMaster gm;
[SerializeField]
private int maxLives = 3;
private static int _remainingLives;
public static int RemainingLives
{
get { return _remainingLives; }
}
void Awake()
{
if (gm == null)
{
gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
}
}
public Transform playerPrefab;
public Transform spawnPoint;
public float spawnDelay = 2;
public Transform spawnPrefab;
public AudioClip respawnAudio;
public CameraShake cameraShake;
[SerializeField]
private GameObject gameOverUI;
void Start()
{
if (cameraShake == null)
{
Debug.LogError("No camera shake referenced in GameMaster");
}
_remainingLives = maxLives;
}
public void EndGame()
{
Debug.Log("GAME OVER");
gameOverUI.SetActive(true);
}
public IEnumerator _RespawnPlayer()
{
AudioSource.PlayClipAtPoint(respawnAudio, new Vector3(spawnPoint.position.x, spawnPoint.position.y, spawnPoint.position.z), 1.0f);
yield return new WaitForSeconds(spawnDelay);
Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation);
GameObject clone = Instantiate(spawnPrefab, spawnPoint.position, spawnPoint.rotation) as GameObject;
Destroy(clone, 3f);
}
public static void KillPlayer(Player player)
{
Destroy(player.gameObject);
_remainingLives -= 1;
if (_remainingLives <= 0)
{
gm.EndGame();
}
else
{
gm.StartCoroutine(gm._RespawnPlayer());
}
}
public static void KillEnemy(Enemy enemy)
{
gm._KillEnemy(enemy);
}
public void _KillEnemy(Enemy _enemy)
{
GameObject _clone = Instantiate(_enemy.deathParticles, _enemy.transform.position, Quaternion.identity) as GameObject;
Destroy(_clone, 2f);
cameraShake.Shake(_enemy.shakeAmt, _enemy.shakeLength);
Destroy(_enemy.gameObject);
}
}