1
00:00:00,000 --> 00:00:03,850
Welcome back, My favorite game developers.

2
00:00:03,854 --> 00:00:05,584
In this video, as you can see,

3
00:00:05,580 --> 00:00:07,860
we have something a bit different.

4
00:00:07,860 --> 00:00:10,620
We have waves, but these waves are not

5
00:00:10,620 --> 00:00:15,440
just regular elements or regular variables.

6
00:00:15,435 --> 00:00:18,455
They have the friend variables inside of them.

7
00:00:18,450 --> 00:00:21,860
And we can create a another wave and another wave.

8
00:00:21,855 --> 00:00:23,405
And as you can see, each one of

9
00:00:23,400 --> 00:00:25,350
those has their own element.

10
00:00:25,350 --> 00:00:29,760
So welcome to the Advanced C-sharp section.

11
00:00:29,759 --> 00:00:33,119
Let's not waste any more time and let's get started.

12
00:00:33,120 --> 00:00:35,880
But I need your full concentration,

13
00:00:35,880 --> 00:00:38,750
your full attention span, and your fall.

14
00:00:38,745 --> 00:00:39,825
Patients with me.

15
00:00:39,825 --> 00:00:42,085
So let's get started.

16
00:00:42,085 --> 00:00:48,125
Oh, okay, So now that we have our random levels,

17
00:00:48,125 --> 00:00:51,785
it's time to create random NME waves.

18
00:00:51,784 --> 00:00:53,484
So we're not just going to

19
00:00:53,480 --> 00:00:55,270
have the regular enemies in here.

20
00:00:55,265 --> 00:00:56,815
I just set them up in

21
00:00:56,810 --> 00:00:59,180
the previous video so that we know what

22
00:00:59,180 --> 00:01:02,060
the general idea is in

23
00:01:02,060 --> 00:01:03,400
each level and just have

24
00:01:03,395 --> 00:01:05,435
a bit of differences between them.

25
00:01:05,435 --> 00:01:07,675
But in this video we are going

26
00:01:07,670 --> 00:01:09,910
to create an enemy spawner.

27
00:01:09,905 --> 00:01:11,465
So let's get started.

28
00:01:11,465 --> 00:01:13,375
The first thing that we're going to do is

29
00:01:13,370 --> 00:01:15,650
we're going to open up the managers.

30
00:01:15,650 --> 00:01:17,590
And we don't have managers in here.

31
00:01:17,585 --> 00:01:19,445
So we're going to go to one of

32
00:01:19,445 --> 00:01:23,255
these that doesn't have a manager and this is it.

33
00:01:23,255 --> 00:01:24,865
And what I'm going to do is I'm

34
00:01:24,860 --> 00:01:26,740
going to go into the prefab.

35
00:01:26,740 --> 00:01:29,870
We have a managers in here and I'm just going to add

36
00:01:29,870 --> 00:01:32,570
the entire managers folder so we can

37
00:01:32,570 --> 00:01:35,660
add managers to whichever scene that we need.

38
00:01:35,660 --> 00:01:36,800
So I'm going to go into

39
00:01:36,800 --> 00:01:39,320
the boss level that we have all the managers in here.

40
00:01:39,320 --> 00:01:41,120
Yes, we do. The cowards.

41
00:01:41,120 --> 00:01:42,470
We don't have the managers or

42
00:01:42,470 --> 00:01:47,690
prefab managers and the managers in here. There we go.

43
00:01:47,690 --> 00:01:51,080
Now we have the game level and all your manager.

44
00:01:51,080 --> 00:01:53,600
And let's go back and see.

45
00:01:53,600 --> 00:01:57,200
So the cowards, yes, save the health.

46
00:01:57,200 --> 00:01:58,580
Do we have managers?

47
00:01:58,579 --> 00:01:59,299
No, we don't.

48
00:01:59,300 --> 00:02:07,870
So again, we go to the prefabs Prefabs Managers.

49
00:02:07,870 --> 00:02:11,620
And there we go. We add the managers to the health room.

50
00:02:11,620 --> 00:02:14,440
Let's go see what else do we have the new we have

51
00:02:14,440 --> 00:02:17,100
managers top. We don't again.

52
00:02:17,095 --> 00:02:21,345
So find the managers at this.

53
00:02:21,340 --> 00:02:23,770
And if you want, you can just skip

54
00:02:23,770 --> 00:02:27,010
this part and go straight to the,

55
00:02:27,010 --> 00:02:28,950
you have in here.

56
00:02:28,945 --> 00:02:31,125
But this is not the prefab,

57
00:02:31,120 --> 00:02:32,680
so I'm going to delete this.

58
00:02:32,680 --> 00:02:33,850
I'm going to add

59
00:02:33,850 --> 00:02:35,650
the actual manager prefab

60
00:02:35,650 --> 00:02:37,600
should have done this in a previous one.

61
00:02:37,600 --> 00:02:40,920
Also scenes, what is this shop?

62
00:02:40,915 --> 00:02:44,085
This Kelly's see, no manager.

63
00:02:44,080 --> 00:02:46,160
And the managers.

64
00:02:46,155 --> 00:02:51,985
And scenes spikes, save managers.

65
00:02:51,980 --> 00:02:54,100
There we go. Boss level.

66
00:02:54,095 --> 00:02:56,335
Managers that we want.

67
00:02:56,330 --> 00:03:00,230
This is not the manager that you are looking for.

68
00:03:00,230 --> 00:03:03,150
So cowards see?

69
00:03:03,154 --> 00:03:04,644
Yes, yes.

70
00:03:04,640 --> 00:03:07,430
Yes, yes, yes.

71
00:03:07,430 --> 00:03:08,330
Okay, great.

72
00:03:08,330 --> 00:03:10,340
So everywhere we do have managers

73
00:03:10,340 --> 00:03:12,820
now it's time to actually create a spawner.

74
00:03:12,815 --> 00:03:14,725
And the best place I believe to

75
00:03:14,720 --> 00:03:17,290
start is in these Kelly's right here.

76
00:03:17,285 --> 00:03:18,685
So in this case,

77
00:03:18,680 --> 00:03:20,810
go to the level manager and let's go

78
00:03:20,810 --> 00:03:23,270
ahead and add a component in here or no,

79
00:03:23,270 --> 00:03:25,150
actually, let's go into the scripts.

80
00:03:25,145 --> 00:03:28,625
And where shall we add the wave spawner?

81
00:03:28,620 --> 00:03:32,050
And let's just add it inside of the managers

82
00:03:32,049 --> 00:03:35,289
in here we're going to create a new C-sharp script,

83
00:03:35,290 --> 00:03:41,100
which is going to be the wave spawner manager.

84
00:03:41,095 --> 00:03:43,455
Hit Enter, we just added the Name Manager.

85
00:03:43,450 --> 00:03:47,090
So again, we have an excuse to other top managers.

86
00:03:47,094 --> 00:03:50,084
So I'm going to go ahead and add it to the level manager.

87
00:03:50,080 --> 00:03:52,420
And in here I'm going to open up the script.

88
00:03:52,420 --> 00:03:55,140
So what do we want to do in here?

89
00:03:55,135 --> 00:03:57,655
We want to create another class.

90
00:03:57,655 --> 00:03:59,805
Why do we want to create a another class?

91
00:03:59,800 --> 00:04:01,240
Well, because first of all,

92
00:04:01,240 --> 00:04:03,330
this is advanced C-sharp.

93
00:04:03,325 --> 00:04:05,455
Second of all, we want to create

94
00:04:05,454 --> 00:04:07,784
a entire different class for

95
00:04:07,780 --> 00:04:09,640
the waves because the waves

96
00:04:09,640 --> 00:04:12,050
have named the waves have enemies,

97
00:04:12,050 --> 00:04:14,270
the waves has a balance of enemies,

98
00:04:14,270 --> 00:04:17,650
the delay between each time we spawned an enemy,

99
00:04:17,645 --> 00:04:18,925
and so on and so forth.

100
00:04:18,920 --> 00:04:21,020
So in here, I'm going to go ahead

101
00:04:21,020 --> 00:04:24,560
and create a public class.

102
00:04:24,560 --> 00:04:27,010
And it's going to be called the wave.

103
00:04:27,005 --> 00:04:29,635
And this wave will have a couple of things.

104
00:04:29,630 --> 00:04:33,860
So first of all, it will have a public String name.

105
00:04:33,860 --> 00:04:36,650
And obviously we don't want to have it always as public,

106
00:04:36,650 --> 00:04:37,700
but in this case,

107
00:04:37,700 --> 00:04:39,590
just so we can save a bit of time without

108
00:04:39,590 --> 00:04:41,920
having to create all the extra things.

109
00:04:41,915 --> 00:04:43,805
We're going to make them public.

110
00:04:43,805 --> 00:04:47,465
Then we'll have a public game object

111
00:04:47,465 --> 00:04:50,975
and an array of enemies.

112
00:04:50,975 --> 00:04:58,415
What an array of enemies and me is. There we go.

113
00:04:58,415 --> 00:05:01,865
Then we'll have a public and

114
00:05:01,865 --> 00:05:06,805
the amount of enemies that will spawn.

115
00:05:06,800 --> 00:05:13,170
And then finally, we'll have a public float spawn delay.

116
00:05:13,660 --> 00:05:17,680
There we go. So these are all of the elements,

117
00:05:17,675 --> 00:05:21,725
or let's say the part of the wave,

118
00:05:21,725 --> 00:05:24,935
all the variables inside of the wave.

119
00:05:24,935 --> 00:05:27,385
If you want to call that variable,

120
00:05:27,380 --> 00:05:28,820
because this is a class,

121
00:05:28,820 --> 00:05:30,730
it's something totally different.

122
00:05:30,725 --> 00:05:33,905
But this is not the only thing that we need to do.

123
00:05:33,905 --> 00:05:36,835
We also need to make sure to say that up here,

124
00:05:36,830 --> 00:05:40,750
this is a system dot serializable.

125
00:05:40,745 --> 00:05:42,695
So we save that.

126
00:05:42,695 --> 00:05:45,065
And what does serializable mean?

127
00:05:45,065 --> 00:05:47,245
It means that now if I open up

128
00:05:47,240 --> 00:05:49,580
the Unity scripts right here,

129
00:05:49,580 --> 00:05:52,300
you will see that.

130
00:05:52,295 --> 00:05:54,215
Okay, nothing happened.

131
00:05:54,215 --> 00:05:55,715
Why is that? Well, because we

132
00:05:55,715 --> 00:05:57,995
also need to do one more thing.

133
00:05:57,995 --> 00:06:02,965
And here we are going to say that this has a public wave.

134
00:06:02,960 --> 00:06:06,140
As you can see now we have a totally new class,

135
00:06:06,139 --> 00:06:08,509
an array of waves.

136
00:06:08,510 --> 00:06:09,800
So we save that.

137
00:06:09,800 --> 00:06:12,320
Now when we go back into Unity,

138
00:06:12,320 --> 00:06:16,970
we shall see that we have the option to create waves.

139
00:06:16,969 --> 00:06:19,719
And if I just add one wave in here,

140
00:06:19,715 --> 00:06:22,885
you'll see that I have different elements for this wave.

141
00:06:22,880 --> 00:06:25,490
And I can have an aim, can have an amount,

142
00:06:25,490 --> 00:06:28,490
can have the spawn delay and the enemies that I want.

143
00:06:28,490 --> 00:06:31,030
And if I add another element in here,

144
00:06:31,025 --> 00:06:32,365
you'll notice that again,

145
00:06:32,360 --> 00:06:34,400
I have a different name, different enemies,

146
00:06:34,400 --> 00:06:37,250
different amounts, and different delays.

147
00:06:37,250 --> 00:06:40,460
So as you can see, this is why recreated or made

148
00:06:40,460 --> 00:06:43,960
sure that this is a system dot serializable.

149
00:06:43,955 --> 00:06:47,245
This will allow us to create different elements of

150
00:06:47,240 --> 00:06:48,830
this and will allow us to

151
00:06:48,830 --> 00:06:50,750
create these types of variables.

152
00:06:50,750 --> 00:06:52,670
So basically we've created

153
00:06:52,670 --> 00:06:56,840
a new variable that has different variables inside of it.

154
00:06:56,840 --> 00:07:00,760
So let's continue on now that we have all of this,

155
00:07:00,755 --> 00:07:04,015
the next thing to do is to obviously go ahead

156
00:07:04,010 --> 00:07:07,220
and start checking wave after wave.

157
00:07:07,220 --> 00:07:10,400
So the first thing we need to do is in here we'll create

158
00:07:10,400 --> 00:07:15,260
a private end and we will keep count of the next wave.

159
00:07:15,260 --> 00:07:17,560
And obviously we will start at 0.

160
00:07:17,555 --> 00:07:19,715
So the first wave will be 0.

161
00:07:19,715 --> 00:07:21,445
And every single time we create

162
00:07:21,440 --> 00:07:23,810
a new wave with a new amount of enemies,

163
00:07:23,810 --> 00:07:25,760
with the new different types of enemies,

164
00:07:25,760 --> 00:07:29,210
we will go to the next wave by increasing it by one.

165
00:07:29,210 --> 00:07:32,750
Then we are going to create a serialized field where

166
00:07:32,750 --> 00:07:37,230
we will keep track of the time between waves.

167
00:07:38,260 --> 00:07:43,100
And let's just set it at five F as a default.

168
00:07:43,100 --> 00:07:44,690
And then we are also going

169
00:07:44,690 --> 00:07:47,170
to keep track of the wave count.

170
00:07:47,165 --> 00:07:52,175
So float wave, I say wave count,

171
00:07:52,175 --> 00:07:54,595
I meant count down.

172
00:07:54,590 --> 00:07:56,380
Okay, save that.

173
00:07:56,375 --> 00:07:58,705
And now when start we need to initialize

174
00:07:58,700 --> 00:08:03,340
the wave countdown to be as the time between waves.

175
00:08:03,335 --> 00:08:06,745
And then we are going to do

176
00:08:06,740 --> 00:08:09,710
something for later on and was thinking,

177
00:08:09,710 --> 00:08:14,800
but now we want to have something also as an extra.

178
00:08:14,795 --> 00:08:17,555
And I think this is the perfect place to create

179
00:08:17,555 --> 00:08:20,755
something of or something we've already covered,

180
00:08:20,750 --> 00:08:22,070
which is an enum.

181
00:08:22,070 --> 00:08:24,320
And why do we want to create an enum?

182
00:08:24,320 --> 00:08:27,770
Because waves will be in three separate states,

183
00:08:27,770 --> 00:08:29,900
we will have a spawning.

184
00:08:29,900 --> 00:08:33,560
So this is where we are spawning every single,

185
00:08:33,560 --> 00:08:37,210
I don't know the time or the delay between the enemies.

186
00:08:37,205 --> 00:08:40,255
For example, every two seconds we spawn a new enemy.

187
00:08:40,250 --> 00:08:41,450
We spawn a new enemy.

188
00:08:41,450 --> 00:08:45,040
At this time, we don't want to be doing certain things

189
00:08:45,035 --> 00:08:48,955
with our wave spawner controller or manager.

190
00:08:48,950 --> 00:08:52,250
I mean, so we need to create different states.

191
00:08:52,250 --> 00:08:54,140
So what I'm going to do is I'm

192
00:08:54,140 --> 00:08:55,940
going to issue a challenge.

193
00:08:55,940 --> 00:08:58,340
And your challenge is to create an enum

194
00:08:58,340 --> 00:09:01,090
for the different states that we are going to have.

195
00:09:01,085 --> 00:09:05,125
So we've already covered enums in the pickup section.

196
00:09:05,120 --> 00:09:07,250
So first of all, create an E naught for

197
00:09:07,250 --> 00:09:09,740
the different spawning states that will have,

198
00:09:09,740 --> 00:09:13,190
will need to have the spawning, waiting and counting.

199
00:09:13,190 --> 00:09:16,340
And finally, all you need to do is create a variable of

200
00:09:16,340 --> 00:09:19,870
this type so we can use it as a reference.

201
00:09:19,865 --> 00:09:24,955
So pause the video right now and go do each one.

202
00:09:24,950 --> 00:09:26,990
Oh, okay, welcome back.

203
00:09:26,990 --> 00:09:28,760
So as I've told you,

204
00:09:28,760 --> 00:09:31,640
in one of the pickups,

205
00:09:31,640 --> 00:09:32,960
whereas the pick-up pickup.

206
00:09:32,960 --> 00:09:35,420
Pickup pickup, a bilayer?

207
00:09:35,420 --> 00:09:40,570
Nope. Item dropper, dope.

208
00:09:40,565 --> 00:09:42,425
Where was it? Where was it?

209
00:09:42,425 --> 00:09:45,265
In the oh, okay.

210
00:09:45,260 --> 00:09:47,450
So in the shop item as you can see,

211
00:09:47,450 --> 00:09:50,540
we've created an enum for the health restore,

212
00:09:50,540 --> 00:09:52,700
health upgrade and the weapon.

213
00:09:52,700 --> 00:09:54,500
And based on each of those,

214
00:09:54,500 --> 00:09:56,410
we have a switch statement.

215
00:09:56,405 --> 00:09:59,695
We are going to do almost exactly the same thing.

216
00:09:59,690 --> 00:10:06,470
So in here I'm going to create a private, private enum.

217
00:10:06,469 --> 00:10:11,979
And this will be these pounding States.

218
00:10:11,975 --> 00:10:16,555
And we are going to have the bombing,

219
00:10:16,550 --> 00:10:21,620
the waiting, and the counting.

220
00:10:21,620 --> 00:10:23,240
And then we'll just create

221
00:10:23,240 --> 00:10:25,280
a variable of this type which is going to be

222
00:10:25,280 --> 00:10:32,580
a private founding states and state.

223
00:10:33,580 --> 00:10:35,960
There we go, save that.

224
00:10:35,960 --> 00:10:37,670
And in here in the start,

225
00:10:37,670 --> 00:10:39,050
what do we want to start with?

226
00:10:39,050 --> 00:10:42,040
Well, we are going to start with the counting.

227
00:10:42,035 --> 00:10:47,675
State is equal to spawning states dot counting.

228
00:10:47,675 --> 00:10:51,205
So we start off by counting down and

229
00:10:51,200 --> 00:10:55,300
then start also we need to make sure that we set.

230
00:10:55,295 --> 00:10:57,995
Oh, so we've already said the wave countdown.

231
00:10:57,995 --> 00:10:59,605
We want to update,

232
00:10:59,600 --> 00:11:01,570
start counting down on the wave.

233
00:11:01,565 --> 00:11:08,405
So if the wave countdown is less than or equal to 0,

234
00:11:08,405 --> 00:11:11,675
then what we're going to do is we're going to check,

235
00:11:11,675 --> 00:11:13,285
first of all, if

236
00:11:13,280 --> 00:11:17,510
the state that we are currently in is different

237
00:11:17,510 --> 00:11:24,200
than the spawning state, dot spawning.

238
00:11:24,200 --> 00:11:28,180
Then what we're going to do is we'll start

239
00:11:28,175 --> 00:11:30,295
spawning while the if

240
00:11:30,290 --> 00:11:32,110
else we haven't finished the countdown,

241
00:11:32,105 --> 00:11:35,005
then we are going to get the countdown and

242
00:11:35,000 --> 00:11:38,950
remove for enrollment time, delta time.

243
00:11:38,945 --> 00:11:41,525
So what is happening in here?

244
00:11:41,525 --> 00:11:43,675
Let's just do a small recap

245
00:11:43,670 --> 00:11:46,370
because all of this is fairly new.

246
00:11:46,370 --> 00:11:50,660
First of all, we have the wave spawner manager,

247
00:11:50,660 --> 00:11:54,560
which is attached to the level manager in here.

248
00:11:54,560 --> 00:11:55,720
Okay.

249
00:11:55,715 --> 00:11:58,325
Wait for this to compile any day now.

250
00:11:58,325 --> 00:12:01,765
Okay, Thank you. So then what do we have?

251
00:12:01,760 --> 00:12:03,980
We have a wave and

252
00:12:03,980 --> 00:12:07,690
every single wave has different elements attached to it.

253
00:12:07,685 --> 00:12:10,555
So what we decided to do is create

254
00:12:10,550 --> 00:12:13,840
an entirely new public class just to represent it.

255
00:12:13,835 --> 00:12:15,355
We could have if we want,

256
00:12:15,350 --> 00:12:18,820
created a separate class just for this one,

257
00:12:18,815 --> 00:12:21,005
in a separate script, just for this one,

258
00:12:21,005 --> 00:12:23,705
and not have it be a mono behavior,

259
00:12:23,705 --> 00:12:26,425
just a stem serializable and system

260
00:12:26,420 --> 00:12:28,280
serializable means that allows

261
00:12:28,280 --> 00:12:30,010
us to create this right here.

262
00:12:30,005 --> 00:12:31,675
And it allows us to change

263
00:12:31,670 --> 00:12:35,720
the different elements right here on how ever we want.

264
00:12:35,720 --> 00:12:37,370
So it can give us the ability to

265
00:12:37,370 --> 00:12:39,730
change the valuables much easier.

266
00:12:39,725 --> 00:12:41,725
So we created the waves,

267
00:12:41,720 --> 00:12:45,890
we keep track of the next wave that might be public

268
00:12:45,890 --> 00:12:48,050
if you want just to make sure we see

269
00:12:48,050 --> 00:12:50,380
everything appropriately, make it public.

270
00:12:50,375 --> 00:12:52,705
We created the time between waves,

271
00:12:52,700 --> 00:12:53,810
the waves come down.

272
00:12:53,810 --> 00:12:55,030
This is pretty simple.

273
00:12:55,025 --> 00:12:57,625
Then we created an enum for the spawning

274
00:12:57,620 --> 00:13:00,830
States because we have different spawning states.

275
00:13:00,830 --> 00:13:03,240
First of all, we can be either spawning,

276
00:13:03,244 --> 00:13:05,794
waiting or we can be counting down.

277
00:13:05,795 --> 00:13:07,765
And then we create one to just

278
00:13:07,760 --> 00:13:09,730
keep track of everything happening,

279
00:13:09,725 --> 00:13:11,785
just like we had in the shop item.

280
00:13:11,780 --> 00:13:15,190
We will later on have different out should I say,

281
00:13:15,185 --> 00:13:17,285
we will have different methods being

282
00:13:17,285 --> 00:13:20,525
executed and the update based on whether we,

283
00:13:20,525 --> 00:13:22,525
on which state we are in,

284
00:13:22,520 --> 00:13:26,150
we will be having different elements, different things.

285
00:13:26,150 --> 00:13:28,690
And this is the first example of it.

286
00:13:28,685 --> 00:13:30,125
If we are counting down,

287
00:13:30,125 --> 00:13:31,775
if we finish counting down

288
00:13:31,775 --> 00:13:33,965
and we're not in a spawning state,

289
00:13:33,965 --> 00:13:35,755
then we will start spawning.

290
00:13:35,750 --> 00:13:37,780
If we haven't finished counting down,

291
00:13:37,775 --> 00:13:40,865
we are just going to remove from the countdown the time,

292
00:13:40,865 --> 00:13:44,095
delta time until it's under 0.

293
00:13:44,090 --> 00:13:46,130
Then we check our responding.

294
00:13:46,130 --> 00:13:50,270
If not, then we will start spawning in the next video,

295
00:13:50,270 --> 00:13:52,300
where we actually will be spawning enemies.

296
00:13:52,295 --> 00:13:53,735
So I hope you enjoy it.

297
00:13:53,735 --> 00:13:55,485
I know this is a bit complicated,

298
00:13:55,489 --> 00:13:57,529
but this is what you signed up for.

299
00:13:57,530 --> 00:14:01,750
You came to the C-sharp advanced section in bonus one.

300
00:14:01,745 --> 00:14:03,545
So I hope you enjoy it.

301
00:14:03,545 --> 00:14:05,935
I hope you are committing your changes and I'll

302
00:14:05,930 --> 00:14:09,480
see you in the next video.

