-
Notifications
You must be signed in to change notification settings - Fork 0
/
spawner2.cs
135 lines (129 loc) · 4.79 KB
/
spawner2.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
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
//Thsi class contain the script that handle the spawning of enemies for level 3.
public class spawner2 : MonoBehaviour
{
public GameObject red;
public GameObject blue;
public GameObject white;
public Tilemap door;
public Transform spawn1;
public Transform spawn2;
public Transform spawn3;
public Transform spawn4;
public Transform spawn5;
public Transform spawn6;
public Transform spawn7;
public Transform spawn8;
private int counter;
private int currentwave = 0;
private int interval;
private int waves;
private bool difficulty;
private GameObject array;
//This function is called at the beginning of the scene to set the number of wave of enemies.
void Start()
{
difficulty = setvol.isHard;
interval = 90;
if(difficulty == true)
{
waves = 5;
}
else
{
waves = 4;
}
}
// Update is called once per frame to check if there is still enemies alive for the current wave and to move to next wave if no enemy left.
void FixedUpdate()
{
array = GameObject.FindWithTag("enermy2");
if (array == null)
{
if (currentwave == waves)
{
door.ClearAllTiles();
}
else
{
if (counter == interval)
{
counter = 0;
currentwave += 1;
spawn(currentwave);
}
counter += 1;
}
}
}
//This function spawns random enermy at certain locations.
void spawn(int wave)
{
if(wave == 1)
{
GameObject enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn1.position, spawn1.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn2.position, spawn2.rotation);
}else if(wave == 2)
{
GameObject enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn1.position, spawn1.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn2.position, spawn2.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn3.position, spawn3.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn4.position, spawn4.rotation);
}else if(wave == 3)
{
GameObject enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn1.position, spawn1.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn2.position, spawn2.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn3.position, spawn3.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn4.position, spawn4.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn5.position, spawn5.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn6.position, spawn6.rotation);
}
else
{
GameObject enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn1.position, spawn1.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn2.position, spawn2.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn3.position, spawn3.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn4.position, spawn4.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn5.position, spawn5.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn6.position, spawn6.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn7.position, spawn7.rotation);
enermy = enermytospawn(Random.Range(0, 2));
Instantiate(enermy, spawn8.position, spawn8.rotation);
}
}
//This function returns the type of enermies to be spawned given a integer.
private GameObject enermytospawn(int index)
{
if(index == 0)
{
return white;
}else if(index == 1)
{
return red;
}else{
return blue;
}
}
}