-
Notifications
You must be signed in to change notification settings - Fork 0
/
WaveUI.cs
102 lines (77 loc) · 2.44 KB
/
WaveUI.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using UnityEngine;
//using System.Collections;
using UnityEngine.UI;
public class WaveUI : MonoBehaviour
{
[SerializeField]
WaveSpawner spawner; //refference for wavespawner that keeps track of countdown,state,etc
[SerializeField]
Animator waveAnimator;
[SerializeField]
Text waveCountdownText;
[SerializeField]
Text waveCountText;
/*
We need to trigger the animation. Inside the UpdateCountingUI, we will trigger the animation only once. We will check if we have switched to the state.
we store the previous state and compare it to the actual state
*/
private WaveSpawner.SpawnState previousState;
// Use this for initialization
void Start()
{
if (spawner == null)
{
Debug.LogError("No spawner referenced!");
this.enabled = false;
}
if (waveAnimator == null)
{
Debug.LogError("No waveAnimator referenced!");
this.enabled = false;
}
if (waveCountdownText == null)
{
Debug.LogError("No waveCountdownText referenced!");
this.enabled = false;
}
if (waveCountText == null)
{
Debug.LogError("No waveCountText referenced!");
this.enabled = false;
}
}
void Update()
{
switch (spawner.State)
{
case WaveSpawner.SpawnState.COUNTING:
UpdateCountingUI();
break;
case WaveSpawner.SpawnState.SPAWNING:
UpdateSpawningUI();
break;
}
previousState = spawner.State;
}
void UpdateCountingUI()
{
if (previousState != WaveSpawner.SpawnState.COUNTING)
{
waveAnimator.SetBool("WaveIncoming", false);
waveAnimator.SetBool("WaveCountdown", true);
// Debug.Log("COUNTING");
}
waveCountdownText.text = ((int)spawner.WaveCountdown).ToString();//updating the text
}
void UpdateSpawningUI()
{
if (previousState != WaveSpawner.SpawnState.SPAWNING)
{
waveAnimator.SetBool("WaveCountdown", false);
waveAnimator.SetBool("WaveIncoming", true);
waveCountText.text = spawner.NextWave.ToString();
// Debug.Log("SPAWNING");
}
}
}