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

2
00:00:03,960 --> 00:00:05,820
In this video, we've actually started

3
00:00:05,820 --> 00:00:08,280
spawning enemies in a smart way.

4
00:00:08,280 --> 00:00:10,910
So now when we run the game,

5
00:00:10,905 --> 00:00:13,445
Let's make this bigger so you

6
00:00:13,440 --> 00:00:15,240
can see properly what's happening.

7
00:00:15,240 --> 00:00:17,150
The after the candidate finishes,

8
00:00:17,145 --> 00:00:18,365
the first enemy appears,

9
00:00:18,360 --> 00:00:19,730
the second enemy appears,

10
00:00:19,725 --> 00:00:22,575
and they just sit there waiting for us to kill them.

11
00:00:22,575 --> 00:00:24,555
So once we do kill them,

12
00:00:24,555 --> 00:00:26,685
Let's try to go them.

13
00:00:27,320 --> 00:00:28,500
Okay.

14
00:00:28,500 --> 00:00:31,560
That's actually, oh, okay, that was embarrassing.

15
00:00:31,560 --> 00:00:33,110
Let's restart the level.

16
00:00:33,105 --> 00:00:35,585
Wait for that. So we

17
00:00:35,580 --> 00:00:38,280
made enemies so good that we cannot kill them.

18
00:00:38,280 --> 00:00:40,780
Okay, So let me try.

19
00:00:42,940 --> 00:00:47,090
Let me get to a certain distance so we can no longer.

20
00:00:47,090 --> 00:00:48,350
So once we call them, you can see

21
00:00:48,350 --> 00:00:49,790
that we have the wave complete.

22
00:00:49,790 --> 00:00:52,700
And then again, we get the enemy spawning because we've

23
00:00:52,700 --> 00:00:55,550
made the amount of enemies and here too for this wave.

24
00:00:55,550 --> 00:01:00,160
So let's not waste any more time and let's get started.

25
00:01:00,155 --> 00:01:02,065
Oh, case.

26
00:01:02,060 --> 00:01:06,010
So let's go ahead and actually starts owning enemies.

27
00:01:06,005 --> 00:01:08,035
The first thing that we're going to do is

28
00:01:08,030 --> 00:01:10,720
obviously create in here some kind

29
00:01:10,715 --> 00:01:15,715
of either a co-routine or we can create also a counter.

30
00:01:15,710 --> 00:01:17,090
But we're going to stick with

31
00:01:17,090 --> 00:01:19,460
the Coubertin And this courting will be

32
00:01:19,460 --> 00:01:23,120
called every time we have this spawn delay.

33
00:01:23,120 --> 00:01:25,780
So this core team will be spawning the enemies.

34
00:01:25,775 --> 00:01:27,625
Anyways, let's get started and we'll

35
00:01:27,620 --> 00:01:29,390
see how everything is working.

36
00:01:29,390 --> 00:01:33,590
So we're going to create an eye enumerator in here.

37
00:01:33,590 --> 00:01:37,400
And it's going to be called the spawn wave.

38
00:01:37,400 --> 00:01:40,640
And the wave that we want to actually spawn.

39
00:01:40,640 --> 00:01:44,840
So wave to spot.

40
00:01:44,840 --> 00:01:48,530
So we already have the wave that we want to span.

41
00:01:48,530 --> 00:01:50,000
It will have its own enemies,

42
00:01:50,000 --> 00:01:52,870
its name, and the amount of enemies it has.

43
00:01:52,865 --> 00:01:55,835
So we're going to create a for loop.

44
00:01:55,835 --> 00:01:58,165
In this for loop, we're going to start

45
00:01:58,160 --> 00:02:01,130
with an integer I equals 0.

46
00:02:01,130 --> 00:02:03,800
We're going to make sure

47
00:02:03,800 --> 00:02:06,970
that we never go over the weight to spawn,

48
00:02:06,965 --> 00:02:08,975
or is it the wave to spawn,

49
00:02:08,975 --> 00:02:11,425
the amount of enemies?

50
00:02:11,420 --> 00:02:14,180
And we are also going to be increasing it by

51
00:02:14,180 --> 00:02:17,050
one every single time.

52
00:02:17,045 --> 00:02:23,095
So in here we are going to create a random enemy number.

53
00:02:23,090 --> 00:02:27,260
And it's going to be the random range.

54
00:02:27,260 --> 00:02:30,100
And this range will be over 0.

55
00:02:30,095 --> 00:02:39,095
And the wave to spawn enemies dot length.

56
00:02:39,090 --> 00:02:42,130
So there we go and remember that enemies,

57
00:02:42,130 --> 00:02:45,370
and here is an array of game objects.

58
00:02:45,370 --> 00:02:48,580
So we want to spend a random enemy in there.

59
00:02:48,580 --> 00:02:50,680
So I'm going in here where we'll say

60
00:02:50,680 --> 00:02:53,580
that some kind of method

61
00:02:53,575 --> 00:02:56,125
to spawn because we want to have it

62
00:02:56,125 --> 00:02:58,915
outside the, this right here.

63
00:02:58,915 --> 00:03:00,955
This will only be the spawn wave.

64
00:03:00,955 --> 00:03:03,105
This will be the enemy spawner in here.

65
00:03:03,100 --> 00:03:04,540
And what we'll do,

66
00:03:04,540 --> 00:03:06,400
and the way this numerator will

67
00:03:06,400 --> 00:03:09,100
work as we are going to yield

68
00:03:09,099 --> 00:03:15,219
return new, wait four seconds.

69
00:03:15,220 --> 00:03:18,310
And it's going to be on the wave.

70
00:03:18,310 --> 00:03:23,270
Respond. Not delay, dot spawn delay.

71
00:03:23,270 --> 00:03:25,010
So what's happening in here?

72
00:03:25,010 --> 00:03:27,020
This is the first time I believe that we

73
00:03:27,020 --> 00:03:29,300
use the yield return

74
00:03:29,300 --> 00:03:34,040
inside of a for loop in an enumerator or a coroutine.

75
00:03:34,040 --> 00:03:36,580
So we go through this loop.

76
00:03:36,575 --> 00:03:39,235
Every single time we choose a random number,

77
00:03:39,230 --> 00:03:41,800
we spawned some kind of enemy,

78
00:03:41,795 --> 00:03:43,825
and then we wait four seconds.

79
00:03:43,820 --> 00:03:46,460
And then again, we spawned an enemy, we spawned an enemy.

80
00:03:46,460 --> 00:03:48,340
So this will allow us to

81
00:03:48,335 --> 00:03:51,085
yield return and call this multiple times,

82
00:03:51,080 --> 00:03:54,280
this spawned wave several times.

83
00:03:54,275 --> 00:03:56,125
And after we do this,

84
00:03:56,120 --> 00:03:57,560
we are going to create also

85
00:03:57,560 --> 00:04:00,250
the actual method that will spawn the enemy.

86
00:04:00,245 --> 00:04:03,185
So spawn enemy.

87
00:04:03,185 --> 00:04:06,085
And in here we're going to say that we will send it

88
00:04:06,080 --> 00:04:11,320
the game object and the enemy to spawn.

89
00:04:11,315 --> 00:04:16,435
And in here we're going to say debug dot log just to

90
00:04:16,430 --> 00:04:18,530
make sure that we know which enemy is

91
00:04:18,530 --> 00:04:20,660
being spawned and everything is working correctly.

92
00:04:20,660 --> 00:04:26,560
So spawning the enemy.

93
00:04:26,555 --> 00:04:30,415
And we're going to give it the enemy to spawn.

94
00:04:30,410 --> 00:04:32,970
But name.

95
00:04:33,040 --> 00:04:37,580
There we go. And we are simply coming to instantiate.

96
00:04:37,580 --> 00:04:44,210
And then she ate the NMI. Too small.

97
00:04:44,210 --> 00:04:48,430
And it's going to be, oops, excuse me.

98
00:04:48,425 --> 00:04:52,225
So it's going to be all the transform dot position

99
00:04:52,220 --> 00:04:56,180
and we transform the row station.

100
00:04:56,180 --> 00:04:58,100
So what is the transform?

101
00:04:58,100 --> 00:05:00,010
Which transform are we talking about?

102
00:05:00,005 --> 00:05:01,585
So because the wave spawner is

103
00:05:01,580 --> 00:05:03,140
attached to the level manager,

104
00:05:03,140 --> 00:05:05,560
this will be the position and the rotation

105
00:05:05,555 --> 00:05:08,855
of the level manager game object in our scene.

106
00:05:08,855 --> 00:05:10,855
And later on, we will be creating

107
00:05:10,850 --> 00:05:13,760
several points on which the enemies will be spawning.

108
00:05:13,760 --> 00:05:15,730
So it will work like that.

109
00:05:15,725 --> 00:05:17,915
We will have some kind of array.

110
00:05:17,915 --> 00:05:20,125
We'll deal with that later on that's now

111
00:05:20,120 --> 00:05:22,640
focused on actually instantiating these enemies.

112
00:05:22,640 --> 00:05:27,130
So spawn enemy, the wave to

113
00:05:27,125 --> 00:05:31,835
spawn enemies at the position

114
00:05:31,834 --> 00:05:35,574
of the random enemy number that we just created.

115
00:05:35,570 --> 00:05:39,190
So I'm going to add an entering here. What are we doing?

116
00:05:39,185 --> 00:05:41,845
We need to also call the coroutine and here,

117
00:05:41,840 --> 00:05:45,530
so before we forget, so co-routine.

118
00:05:45,530 --> 00:05:50,320
Spawn, spawn, enemies, wave.

119
00:05:50,315 --> 00:05:51,205
Yep, there we go.

120
00:05:51,200 --> 00:05:53,800
And which way should we be spawning?

121
00:05:53,795 --> 00:05:56,915
While in here we're just going to say that it's the wave,

122
00:05:56,915 --> 00:06:00,895
waves at the position next wave.

123
00:06:00,890 --> 00:06:02,300
So it's going to be probably

124
00:06:02,300 --> 00:06:04,840
0 right now because next wave,

125
00:06:04,835 --> 00:06:06,365
whereas the next wave,

126
00:06:06,365 --> 00:06:08,755
it starts off at 0 right here.

127
00:06:08,750 --> 00:06:10,810
So it's going to be the first wave

128
00:06:10,805 --> 00:06:13,195
that's for just experimenting for now,

129
00:06:13,190 --> 00:06:14,630
that's focused on what this does.

130
00:06:14,630 --> 00:06:18,130
So a co-routine which starts if we

131
00:06:18,125 --> 00:06:19,285
make sure that we are not

132
00:06:19,280 --> 00:06:21,950
spawning of the countdown is less than 0,

133
00:06:21,950 --> 00:06:23,180
we are not spawning,

134
00:06:23,180 --> 00:06:25,490
we are ready to start spawning.

135
00:06:25,490 --> 00:06:29,090
Then we start the coating in here we have the loop will

136
00:06:29,090 --> 00:06:30,830
loop through the amount of enemies on

137
00:06:30,830 --> 00:06:32,750
the wave that we receive.

138
00:06:32,750 --> 00:06:36,020
As a coroutine, we create a random number.

139
00:06:36,020 --> 00:06:39,370
We spawn a random enemy which just has the debug

140
00:06:39,365 --> 00:06:41,275
to tell us which enemy is being spawned

141
00:06:41,270 --> 00:06:43,280
will probably remove this later on.

142
00:06:43,280 --> 00:06:48,170
And then we instantiate the actual enemy on the manager.

143
00:06:48,170 --> 00:06:50,150
And then what happens? We yield return,

144
00:06:50,150 --> 00:06:53,380
wait four seconds and then spawn in other enemy.

145
00:06:53,375 --> 00:06:56,405
So before this loop than again is called,

146
00:06:56,405 --> 00:06:58,405
we have to weigh the spawn delay

147
00:06:58,400 --> 00:07:00,710
that is designated to us.

148
00:07:00,710 --> 00:07:02,500
So I'm going to save all of that.

149
00:07:02,495 --> 00:07:05,015
I'm going to go back and unity.

150
00:07:05,015 --> 00:07:08,665
And let's see what we have in here as a level manager.

151
00:07:08,660 --> 00:07:11,690
Wait for this to compile anything.

152
00:07:11,690 --> 00:07:13,790
Okay, so we go to

153
00:07:13,790 --> 00:07:17,140
the manager's level manager and what do we have in here?

154
00:07:17,135 --> 00:07:18,535
I was playing around,

155
00:07:18,530 --> 00:07:21,050
maybe I did not do this in the video.

156
00:07:21,050 --> 00:07:22,750
So we have this wave right here.

157
00:07:22,745 --> 00:07:24,155
It's the skeleton wave.

158
00:07:24,155 --> 00:07:26,125
The enemies that we have in here are

159
00:07:26,120 --> 00:07:29,450
the skeleton enemy and the cowardly flying high.

160
00:07:29,450 --> 00:07:31,720
The amount of enemies we want is to

161
00:07:31,715 --> 00:07:34,255
and respond lay will be two seconds.

162
00:07:34,250 --> 00:07:35,330
I'm going to save this.

163
00:07:35,330 --> 00:07:37,840
Where's the level manager and our world?

164
00:07:37,835 --> 00:07:39,935
It's not on the 000.

165
00:07:39,935 --> 00:07:41,755
Let's put it back to 0,

166
00:07:41,750 --> 00:07:43,670
so it's right in front of our player.

167
00:07:43,670 --> 00:07:46,280
And let's run the game and see what it looks like.

168
00:07:46,280 --> 00:07:50,300
So now 12, we should see the wave countdown.

169
00:07:50,300 --> 00:07:53,450
There we go and whoa,

170
00:07:53,450 --> 00:07:56,180
that's too much enemies.

171
00:07:56,180 --> 00:07:59,020
Let's see what we did wrong in here.

172
00:07:59,015 --> 00:08:00,395
So we save that.

173
00:08:00,395 --> 00:08:01,645
What's happening in here,

174
00:08:01,640 --> 00:08:04,430
we are checking the countdown is less than 0.

175
00:08:04,430 --> 00:08:06,760
Are we not in the spawning state?

176
00:08:06,755 --> 00:08:08,305
Well, let's see. We start

177
00:08:08,300 --> 00:08:10,330
off with the counting, so we're not.

178
00:08:10,325 --> 00:08:14,185
So obviously we need to change our states in here.

179
00:08:14,180 --> 00:08:19,160
So before we actually create the loop or start the loop,

180
00:08:19,160 --> 00:08:20,840
we are going to say that we are in

181
00:08:20,840 --> 00:08:22,910
a state which is equal to

182
00:08:22,910 --> 00:08:26,980
the spawning States, but spawning.

183
00:08:26,975 --> 00:08:29,725
And then when we finish spawning,

184
00:08:29,720 --> 00:08:32,590
we are going to go into a state,

185
00:08:32,585 --> 00:08:34,585
which is the weighting.

186
00:08:34,580 --> 00:08:37,580
So we're waiting for the enemies to be spawn.

187
00:08:37,580 --> 00:08:42,710
So now we start before we actually go through the loop,

188
00:08:42,710 --> 00:08:43,940
we said the state.

189
00:08:43,940 --> 00:08:46,250
So now this will not be called every single

190
00:08:46,250 --> 00:08:48,940
time and we will not have that many enemies.

191
00:08:48,935 --> 00:08:51,055
Let's again test this out.

192
00:08:51,050 --> 00:08:55,500
Run the game. We can see the countdown in here.

193
00:08:55,495 --> 00:08:57,855
I made it public. There we go.

194
00:08:57,850 --> 00:09:01,720
So 0, we get the enemy and he starts shooting.

195
00:09:01,720 --> 00:09:03,040
Then we get another enemy,

196
00:09:03,040 --> 00:09:04,740
and then we gave them another enemy,

197
00:09:04,735 --> 00:09:07,005
and it's being called every two seconds.

198
00:09:07,000 --> 00:09:09,510
So look at these little cowers right here.

199
00:09:09,505 --> 00:09:13,215
This is a really nice cool game mechanic, as you can see,

200
00:09:13,210 --> 00:09:18,100
every two seconds, 1212, and there we go.

201
00:09:18,100 --> 00:09:19,230
So as you can see,

202
00:09:19,225 --> 00:09:21,865
enemies are being called every single second.

203
00:09:21,865 --> 00:09:23,695
But you now might be wondering,

204
00:09:23,695 --> 00:09:26,005
why do we have so many enemies,

205
00:09:26,005 --> 00:09:27,735
even though we said that the amount

206
00:09:27,730 --> 00:09:29,800
of enemies should be only too.

207
00:09:29,800 --> 00:09:31,690
Well. It's because in here,

208
00:09:31,690 --> 00:09:35,310
we don't actually have the wave countdown resetting.

209
00:09:35,305 --> 00:09:38,905
Again, something that we will deal with later on.

210
00:09:38,900 --> 00:09:42,920
But let's first of all think of when will we be

211
00:09:42,920 --> 00:09:47,830
actually resetting the wave and when does an actual wave?

212
00:09:47,825 --> 00:09:52,255
And so we can either create a time between wave.

213
00:09:52,250 --> 00:09:55,130
So let's say the first wave and the second wave,

214
00:09:55,130 --> 00:09:56,840
there is a delay between them.

215
00:09:56,840 --> 00:09:59,960
Or we can have some really nice mechanic and give

216
00:09:59,960 --> 00:10:03,430
our layer or the person that's playing our game

217
00:10:03,425 --> 00:10:06,445
a chance to go ahead and kill all of

218
00:10:06,440 --> 00:10:10,900
the enemies in this wave before the next wave comes on.

219
00:10:10,895 --> 00:10:13,075
So this is what we are going to do.

220
00:10:13,070 --> 00:10:14,780
And to do that, we are going to

221
00:10:14,780 --> 00:10:17,270
create some kind of method

222
00:10:17,269 --> 00:10:21,949
that will keep track of whether an enemy has died or not.

223
00:10:21,950 --> 00:10:24,940
So let's go back down here.

224
00:10:24,935 --> 00:10:27,055
And after the spawn enemy,

225
00:10:27,050 --> 00:10:29,450
we are going to create a private.

226
00:10:29,450 --> 00:10:31,490
There's going to be a Boolean,

227
00:10:31,490 --> 00:10:36,740
and it's going to be the enemies or alive.

228
00:10:36,740 --> 00:10:39,130
And this will return true if

229
00:10:39,125 --> 00:10:41,765
all the enemies are alive or no.

230
00:10:41,765 --> 00:10:45,625
Oh yes, if all of the enemies are alive and false,

231
00:10:45,620 --> 00:10:48,730
if one of them or none of them are alive.

232
00:10:48,725 --> 00:10:50,845
So in here what I'm going to say,

233
00:10:50,840 --> 00:10:53,150
I'm going to create an if condition.

234
00:10:53,150 --> 00:10:56,890
And I'm going to have the final object of type.

235
00:10:56,885 --> 00:11:00,905
And objects of type actually not find objects,

236
00:11:00,905 --> 00:11:03,995
find up objects of type.

237
00:11:03,995 --> 00:11:05,925
And the enemy controller,

238
00:11:05,929 --> 00:11:09,709
I'll be looking for the enemy controller dot length.

239
00:11:09,710 --> 00:11:12,850
And it's going to be equal to 0.

240
00:11:12,845 --> 00:11:18,185
And if it is, then we are going to return false.

241
00:11:18,185 --> 00:11:22,105
So false, that means that all the enemies have died.

242
00:11:22,100 --> 00:11:24,800
And then if we go through

243
00:11:24,800 --> 00:11:27,230
this one and we don't return false,

244
00:11:27,230 --> 00:11:30,890
then we are going to return true.

245
00:11:30,890 --> 00:11:34,460
That means that the enemies are still alive.

246
00:11:34,460 --> 00:11:36,920
So now we have a wave

247
00:11:36,920 --> 00:11:39,890
or of making sure whether our enemies

248
00:11:39,890 --> 00:11:42,400
have all been depleted and we will be

249
00:11:42,395 --> 00:11:45,625
able to use it right here as a condition somehow.

250
00:11:45,620 --> 00:11:49,280
But there is a small problem that is bothering me.

251
00:11:49,280 --> 00:11:52,100
The find objects of type on

252
00:11:52,100 --> 00:11:55,780
the enemy controller is actually a very cumbersome,

253
00:11:55,775 --> 00:11:58,105
let's say operation on the system.

254
00:11:58,100 --> 00:12:01,070
It takes up a lot of resources every

255
00:12:01,070 --> 00:12:02,840
time to go through all the objects

256
00:12:02,840 --> 00:12:04,190
on the enemy controller,

257
00:12:04,190 --> 00:12:06,950
which is sometimes not very necessary.

258
00:12:06,950 --> 00:12:10,430
So what do we want to do is we want to have some kind

259
00:12:10,430 --> 00:12:14,560
of a timer on the enemies are alive checker.

260
00:12:14,555 --> 00:12:16,405
So we don't actually check

261
00:12:16,400 --> 00:12:19,670
every single frame if all the enemies are dead.

262
00:12:19,670 --> 00:12:21,550
But instead, we have this

263
00:12:21,545 --> 00:12:23,765
being checked every couple of seconds.

264
00:12:23,765 --> 00:12:26,905
So I'm going to issue it to you as a challenge,

265
00:12:26,900 --> 00:12:29,470
and your challenge is to delay checking.

266
00:12:29,465 --> 00:12:30,595
So first of all,

267
00:12:30,590 --> 00:12:32,480
you'll need to create a variable for

268
00:12:32,480 --> 00:12:35,390
the time between checking for enemies.

269
00:12:35,390 --> 00:12:38,360
In the Boolean method makes sure that we don't

270
00:12:38,360 --> 00:12:42,130
look all the enemies except when the time is done.

271
00:12:42,125 --> 00:12:45,535
Pay attention to where we should reset this counter.

272
00:12:45,530 --> 00:12:47,540
So this will be very important.

273
00:12:47,540 --> 00:12:49,000
So with that said,

274
00:12:48,995 --> 00:12:53,635
pause the video right now and go do each Shannon.

275
00:12:53,630 --> 00:12:56,270
Okay, welcome back.

276
00:12:56,270 --> 00:12:59,110
So I'm going to scroll up in here.

277
00:12:59,105 --> 00:13:03,055
And I'm going to create a private float.

278
00:13:03,050 --> 00:13:10,030
The time between enemy search, between enemy search.

279
00:13:10,025 --> 00:13:12,455
And let's say it's one F.

280
00:13:12,455 --> 00:13:15,055
So 1 second. Every 1 second we check

281
00:13:15,050 --> 00:13:17,840
for all of the enemies of the debt.

282
00:13:17,840 --> 00:13:22,720
And then in here I'm going to say that the time between

283
00:13:22,715 --> 00:13:29,015
search is being reduced by Time.deltaTime,

284
00:13:29,015 --> 00:13:30,505
every single frame, and this will

285
00:13:30,500 --> 00:13:32,410
be called every single frame.

286
00:13:32,405 --> 00:13:34,085
And then down here,

287
00:13:34,085 --> 00:13:35,635
I'm going to check before we

288
00:13:35,630 --> 00:13:37,520
actually check for all the objects.

289
00:13:37,520 --> 00:13:44,480
If the time between search is less than or equal to 0,

290
00:13:44,480 --> 00:13:51,530
then we will be searching. There we go.

291
00:13:51,530 --> 00:13:54,620
And then when do we actually reset this?

292
00:13:54,620 --> 00:13:56,210
So once the time between

293
00:13:56,210 --> 00:13:58,510
search is less than or equal to 0,

294
00:13:58,505 --> 00:14:02,135
we start by checking if all of the enemies have died.

295
00:14:02,135 --> 00:14:04,195
And we also can go

296
00:14:04,190 --> 00:14:07,000
ahead and reset this time between searches.

297
00:14:06,995 --> 00:14:11,425
And I'm going to set it to 1.5 because I don't

298
00:14:11,420 --> 00:14:13,490
think that this is something

299
00:14:13,490 --> 00:14:15,970
that you might want to change in the inspector,

300
00:14:15,965 --> 00:14:17,635
the time between enemy searches,

301
00:14:17,630 --> 00:14:19,680
this can be pretty standard.

302
00:14:19,684 --> 00:14:21,384
But if you think that you

303
00:14:21,380 --> 00:14:23,600
might need to change this variable,

304
00:14:23,600 --> 00:14:25,880
obviously this one f will not work.

305
00:14:25,880 --> 00:14:27,080
You need to go up here,

306
00:14:27,080 --> 00:14:28,910
create a separate variable

307
00:14:28,910 --> 00:14:30,970
if you did that, congratulations,

308
00:14:30,965 --> 00:14:34,975
this is the better step or the better way of thinking,

309
00:14:34,970 --> 00:14:37,330
the better game design maybe.

310
00:14:37,325 --> 00:14:38,875
But for me, I believe this

311
00:14:38,870 --> 00:14:40,660
will be something very constant,

312
00:14:40,655 --> 00:14:42,175
something that will not change.

313
00:14:42,170 --> 00:14:44,450
I don't think we will ever have to change

314
00:14:44,450 --> 00:14:47,090
the time between enemy searches.

315
00:14:47,090 --> 00:14:48,320
Will that finished?

316
00:14:48,320 --> 00:14:50,410
Let's go back up in here.

317
00:14:50,405 --> 00:14:53,245
And we need to make sure that we,

318
00:14:53,240 --> 00:14:56,210
Where is it in here and update.

319
00:14:56,210 --> 00:14:57,840
We are going to check

320
00:14:57,840 --> 00:15:05,210
the state is equal to the spawning states dot waiting.

321
00:15:05,210 --> 00:15:08,360
So that means we are constantly

322
00:15:08,360 --> 00:15:11,720
spawning enemies and we are in the waiting.

323
00:15:11,720 --> 00:15:15,200
So we check after we obviously finished this for loop,

324
00:15:15,200 --> 00:15:18,470
we check is the state waiting.

325
00:15:18,470 --> 00:15:20,720
Then if it is in here,

326
00:15:20,720 --> 00:15:25,690
we are going to check if the enemies are alive.

327
00:15:25,685 --> 00:15:29,275
And notice that we added this exclamation mark,

328
00:15:29,270 --> 00:15:31,370
which means the exact opposite.

329
00:15:31,370 --> 00:15:34,220
So if all of the enemies have Lloyd are going to

330
00:15:34,220 --> 00:15:38,450
save debug dot log, wave.

331
00:15:38,450 --> 00:15:40,070
Complete.

332
00:15:40,069 --> 00:15:41,629
Save that.

333
00:15:41,630 --> 00:15:44,000
And else, if it's not,

334
00:15:44,000 --> 00:15:46,690
then we are going to simply return.

335
00:15:46,685 --> 00:15:48,145
And why are we doing this?

336
00:15:48,140 --> 00:15:49,610
Why are we saying return?

337
00:15:49,610 --> 00:15:52,390
We said that returned means that we don't do

338
00:15:52,385 --> 00:15:56,435
anything else inside of the method, especially in update.

339
00:15:56,435 --> 00:15:59,335
Why? Because once the wave is complete,

340
00:15:59,330 --> 00:16:01,580
we don't want to go back into the wave,

341
00:16:01,580 --> 00:16:04,330
can now check if we are not in spawning,

342
00:16:04,325 --> 00:16:05,995
which we will be not n

343
00:16:05,990 --> 00:16:08,260
because we are obviously and the waiting

344
00:16:08,255 --> 00:16:10,135
and start the recording again and

345
00:16:10,130 --> 00:16:12,740
start creating the enemies again.

346
00:16:12,740 --> 00:16:14,630
So once the wave is complete,

347
00:16:14,630 --> 00:16:18,830
we want to stop the whole update from working.

348
00:16:18,830 --> 00:16:20,200
So I'm going to save that.

349
00:16:20,195 --> 00:16:22,195
I'm going to go back into my gain.

350
00:16:22,190 --> 00:16:26,720
And now we should see that when we run the game.

351
00:16:26,720 --> 00:16:31,270
So we get, after five seconds of Countdown,

352
00:16:31,265 --> 00:16:32,915
we get the count the enemy.

353
00:16:32,915 --> 00:16:35,995
After two seconds we can another count the enemy.

354
00:16:35,990 --> 00:16:38,030
And there we go.

355
00:16:38,030 --> 00:16:41,000
You can see that we have stopped everything so we

356
00:16:41,000 --> 00:16:44,260
no longer get more enemies that we have to.

357
00:16:44,255 --> 00:16:46,015
So I'm going to try to kill those.

358
00:16:46,010 --> 00:16:47,540
So we have both of them.

359
00:16:47,540 --> 00:16:48,920
And as you can see, again,

360
00:16:48,920 --> 00:16:51,940
the wave has been completed and then the enemies

361
00:16:51,935 --> 00:16:55,375
start spawning again. Okay, great.

362
00:16:55,370 --> 00:16:57,700
So with that out of the way,

363
00:16:57,695 --> 00:16:59,875
make sure to commit your changes.

364
00:16:59,870 --> 00:17:01,790
I hope you enjoy it and I'll see you in

365
00:17:01,790 --> 00:17:03,800
the next video where we'll be

366
00:17:03,800 --> 00:17:06,040
spawning points for multiple waves

367
00:17:06,035 --> 00:17:08,225
and completing all of them,

368
00:17:08,225 --> 00:17:09,385
killing all the enemies,

369
00:17:09,380 --> 00:17:10,820
completing all the way,

370
00:17:10,820 --> 00:17:14,030
and maybe having some kind of really nice message.

371
00:17:14,030 --> 00:17:16,230
So see you then.

