-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaptureZoneCode.cs
More file actions
137 lines (123 loc) · 4.07 KB
/
CaptureZoneCode.cs
File metadata and controls
137 lines (123 loc) · 4.07 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CaptureZoneCode : MonoBehaviour
{
public int captureTime = 6;
public List<GameObject> spawners = new List<GameObject>();
public List<GameObject> nextSpawners = new List<GameObject>();
public List<GameObject> instantSpawns = new List<GameObject>();
public ProgressBar progressBar;
public GameObject playerHUD;
public GameObject wall;
public GameObject allRemainingIcos;
public AudioClip[] activationSounds;
private AudioSource audioSource;
private float zoneTime = 0.0f;
private bool inZone = false;
private bool cleared = false;
private bool shrinkedSpawner = false;
private float scaleValue = 1f;
private float shrinkSpeed = 2f;
private ProgressBar activeBar;
void Start()
{
audioSource = GetComponent<AudioSource>();
}
void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "Player" && !cleared)
{
activeBar = Instantiate(progressBar, playerHUD.transform);
activeBar.SetMaxValue(captureTime);
inZone = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.transform.tag == "Player" && !cleared)
{
inZone = false;
Destroy(activeBar.gameObject);
zoneTime = 0.0f;
}
}
void Update()
{
if (!cleared)
{
if (inZone == true)
{
zoneTime += Time.deltaTime;
activeBar.SetValue(zoneTime);
if (!audioSource.isPlaying)
{
audioSource.clip = activationSounds[0];
audioSource.PlayOneShot(audioSource.clip);
}
}
else
{
zoneTime = 0.0f;
audioSource.Stop();
}
if (zoneTime >= captureTime)
{
foreach (var spawner in spawners)
{
spawner.GetComponent<IcoSpawner>().StopAllCoroutines();
Destroy(spawner, 2f);
}
audioSource.Stop();
audioSource.clip = activationSounds[1];
audioSource.PlayOneShot(audioSource.clip);
zoneTime = 0.0f;
inZone = false;
Destroy(activeBar.gameObject);
Destroy(transform.GetChild(0).gameObject);
if (nextSpawners != null)
{
foreach (var spawner in nextSpawners)
spawner.SetActive(true);
}
cleared = true;
Destroy(wall);
if (instantSpawns != null)
{
foreach (var spawn in instantSpawns)
spawn.SetActive(true);
}
if (allRemainingIcos != null)
{
for (int i = 0; i < 8; i ++)
{
Transform holder = allRemainingIcos.transform.GetChild(i);
foreach (Transform child in holder)
child.GetComponent<Target>().Die();
}
}
}
}
else if (!shrinkedSpawner)
{
if (scaleValue > 0f)
{
scaleValue -= shrinkSpeed * Time.deltaTime;
Vector3 scale = new Vector3(scaleValue, scaleValue, scaleValue);
foreach (var spawner in spawners)
{
spawner.transform.localScale = scale;
}
}
else
{
foreach (var spawner in spawners)
{
spawner.transform.localScale = new Vector3(0, 0, 0);
}
shrinkedSpawner = true;
}
}
}
}