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

2
00:00:03,330 --> 00:00:05,640
In this video, we are actually going to be

3
00:00:05,640 --> 00:00:08,270
completing the wave, starting new waves.

4
00:00:08,265 --> 00:00:09,855
Once we finish all of them,

5
00:00:09,855 --> 00:00:11,975
we have the option to open the doors.

6
00:00:11,970 --> 00:00:14,360
Don't open them yet, but we will.

7
00:00:14,355 --> 00:00:17,445
Unfortunately, because this might take a lot of fun.

8
00:00:17,445 --> 00:00:19,995
I'm not going to demonstrate it in the intro,

9
00:00:19,995 --> 00:00:22,865
but feel free to watch the video.

10
00:00:22,860 --> 00:00:25,830
You will see that it is actually working.

11
00:00:25,830 --> 00:00:27,320
We made sure that it does.

12
00:00:27,315 --> 00:00:29,475
We always make sure that it does.

13
00:00:29,475 --> 00:00:32,135
Okay. So I think we are at a good point.

14
00:00:32,130 --> 00:00:33,230
So as you can see,

15
00:00:33,225 --> 00:00:35,265
you sought to enemies randomly spawning.

16
00:00:35,265 --> 00:00:37,205
The time has finished. Let me okay.

17
00:00:37,200 --> 00:00:40,200
So the spine on the same position we call them,

18
00:00:40,195 --> 00:00:42,025
we should see in the Inspector that

19
00:00:42,020 --> 00:00:43,760
we've completed all the waves,

20
00:00:43,760 --> 00:00:45,760
which means we will open the doors.

21
00:00:45,755 --> 00:00:49,285
So let's not waste any more time and let's get started.

22
00:00:49,280 --> 00:00:50,870
Oh, okay.

23
00:00:50,870 --> 00:00:53,950
So what is happening right now?

24
00:00:53,945 --> 00:00:57,275
First of all, I forgot to stage all of my files.

25
00:00:57,275 --> 00:01:01,615
I'm going to call it an instantiate,

26
00:01:01,610 --> 00:01:05,030
various types of enemies.

27
00:01:05,030 --> 00:01:06,730
This was the previous video,

28
00:01:06,725 --> 00:01:09,565
but now let's focus on what's happening in yield.

29
00:01:09,560 --> 00:01:12,340
So you remember that in the last one,

30
00:01:12,335 --> 00:01:14,965
we actually started completing waves,

31
00:01:14,960 --> 00:01:17,450
but not White so

32
00:01:17,450 --> 00:01:20,150
much because even though we finished a wave,

33
00:01:20,150 --> 00:01:22,370
you might have noticed that Then again,

34
00:01:22,370 --> 00:01:24,650
and it means start spawning.

35
00:01:24,650 --> 00:01:25,940
Why is that?

36
00:01:25,940 --> 00:01:27,680
Well, that's because obviously

37
00:01:27,680 --> 00:01:31,270
the wave countdown is still less than 0.

38
00:01:31,265 --> 00:01:33,255
We are going back to spawning.

39
00:01:33,259 --> 00:01:35,659
And well, obviously, sorry,

40
00:01:35,660 --> 00:01:37,730
we are not going back to spawning,

41
00:01:37,730 --> 00:01:41,140
so we are always starting with co-routine again.

42
00:01:41,135 --> 00:01:42,535
So what do we need?

43
00:01:42,530 --> 00:01:44,590
Do we need to actually,

44
00:01:44,585 --> 00:01:46,735
first of all start a new wave?

45
00:01:46,730 --> 00:01:48,260
And second of all, we need to

46
00:01:48,260 --> 00:01:50,000
reset all of that and make sure

47
00:01:50,000 --> 00:01:53,390
that at the end we stop the all the waves.

48
00:01:53,390 --> 00:01:54,650
We've finished all the waves.

49
00:01:54,650 --> 00:01:56,800
We can open the door and so on.

50
00:01:56,795 --> 00:01:58,015
Man. Not only that,

51
00:01:58,010 --> 00:01:59,240
we also in this video,

52
00:01:59,240 --> 00:02:01,040
we want to create several points

53
00:02:01,040 --> 00:02:03,260
from which the enemies will be spawning.

54
00:02:03,260 --> 00:02:04,910
So we have our hands full.

55
00:02:04,910 --> 00:02:06,530
Let's not waste any more time.

56
00:02:06,530 --> 00:02:08,630
What should we be doing in here?

57
00:02:08,630 --> 00:02:12,340
First of all, I'm going to scroll down and create

58
00:02:12,335 --> 00:02:17,875
a new void, Start New Wave.

59
00:02:17,870 --> 00:02:21,820
And what happened?

60
00:02:21,815 --> 00:02:24,385
And in here I'm going to say that as

61
00:02:24,380 --> 00:02:26,420
soon as we want to start a new wave,

62
00:02:26,420 --> 00:02:29,300
then we are going to set the state to

63
00:02:29,300 --> 00:02:32,620
the spawning states that counting.

64
00:02:32,615 --> 00:02:36,475
So in here we are counting for the next wave and

65
00:02:36,470 --> 00:02:38,390
the wave countdown will

66
00:02:38,390 --> 00:02:42,000
be equal to the time between waves.

67
00:02:42,400 --> 00:02:48,850
Folks, not enemy search the time between waves.

68
00:02:48,845 --> 00:02:51,215
And then in here we're going to check

69
00:02:51,215 --> 00:02:53,815
if the next wave plus

70
00:02:53,810 --> 00:02:59,750
1 is equal to the waves got length.

71
00:02:59,750 --> 00:03:02,390
So that means that we are on the last way,

72
00:03:02,390 --> 00:03:04,820
that the next wave as the last one.

73
00:03:04,820 --> 00:03:10,390
Then we're going to say that debug dot log.

74
00:03:10,385 --> 00:03:19,415
And in here we'll say we've completed all the waves.

75
00:03:19,415 --> 00:03:22,255
And I just said something I believe,

76
00:03:22,250 --> 00:03:23,960
isn't that true in here?

77
00:03:23,960 --> 00:03:26,420
First of all, we need to add two equals,

78
00:03:26,420 --> 00:03:28,550
equals to compare when we add one equal,

79
00:03:28,550 --> 00:03:29,950
that means we are assigning

80
00:03:29,945 --> 00:03:32,215
two equals as when we comparing.

81
00:03:32,210 --> 00:03:35,480
And I said in here that the next wave is the last one.

82
00:03:35,480 --> 00:03:39,800
No, When I said next week plus 1 equals wave that length,

83
00:03:39,800 --> 00:03:42,320
that means that the next wave right here

84
00:03:42,320 --> 00:03:45,290
without the plus one as the last index.

85
00:03:45,290 --> 00:03:50,870
So next wave plus 1 is the size of the entire array,

86
00:03:50,870 --> 00:03:52,630
which is the waves dot length.

87
00:03:52,625 --> 00:03:55,805
So that means that we are currently on the last one,

88
00:03:55,805 --> 00:03:57,505
which means that debug dot log

89
00:03:57,500 --> 00:03:59,930
says we've completed all the waves.

90
00:03:59,930 --> 00:04:02,480
And we'll just add a comment here.

91
00:04:02,480 --> 00:04:04,420
We can open the doors,

92
00:04:04,415 --> 00:04:11,095
open doors, get rewards, etc.

93
00:04:11,090 --> 00:04:14,480
Okay, And then once we finish,

94
00:04:14,480 --> 00:04:16,370
so if we're not on the last wave,

95
00:04:16,370 --> 00:04:17,600
what are we going to do?

96
00:04:17,600 --> 00:04:22,780
Well, we're going to say that the next wave, plus, plus,

97
00:04:22,775 --> 00:04:28,535
so plus, plus, so we increased the next week by one.

98
00:04:28,535 --> 00:04:32,485
So now all we got to do is when we check for

99
00:04:32,480 --> 00:04:36,460
the enemies and update and the wave is complete,

100
00:04:36,455 --> 00:04:41,455
we are going to start a new waived.

101
00:04:41,450 --> 00:04:44,380
So I believe that's all that we need to do.

102
00:04:44,375 --> 00:04:46,315
So I'm going to go back into

103
00:04:46,310 --> 00:04:48,440
my game in here and I'm going

104
00:04:48,440 --> 00:04:53,060
to say any day now, please.

105
00:04:53,060 --> 00:04:55,130
So in the level manager, let's see,

106
00:04:55,130 --> 00:04:59,240
we have let's make sure that we don't have any problems.

107
00:04:59,240 --> 00:05:02,180
I'm going to change this to the,

108
00:05:02,180 --> 00:05:03,880
where are the enemies?

109
00:05:03,875 --> 00:05:09,395
Let's make it smaller or are the enemy prefabs, enemy?

110
00:05:09,395 --> 00:05:10,915
Okay, so we have the petroleum,

111
00:05:10,910 --> 00:05:11,960
let's make sure that

112
00:05:11,960 --> 00:05:15,130
the first wave only has a skeleton enemies.

113
00:05:15,125 --> 00:05:19,315
And we'll create a second wave in here, which is the,

114
00:05:19,310 --> 00:05:22,310
let's just call it high wave because we have

115
00:05:22,310 --> 00:05:25,960
the flying eyes and we are going to have both.

116
00:05:25,955 --> 00:05:27,715
Of these be the cowardly.

117
00:05:27,710 --> 00:05:31,280
So we will know when we are in the next wave.

118
00:05:31,280 --> 00:05:32,870
So I'm going to save all of that.

119
00:05:32,870 --> 00:05:34,540
I'm going to check in here,

120
00:05:34,535 --> 00:05:36,065
okay, time between waves.

121
00:05:36,065 --> 00:05:38,225
Let's run the game and see how that looks.

122
00:05:38,225 --> 00:05:39,835
So I'm going to run

123
00:05:39,830 --> 00:05:43,350
the game and we should only see skeletons.

124
00:05:43,420 --> 00:05:46,030
Skeleton, there we go.

125
00:05:46,025 --> 00:05:47,395
Skeleton, there we go.

126
00:05:47,390 --> 00:05:49,220
So now when we kill them,

127
00:05:49,220 --> 00:05:54,920
we should only see flying crows after the five seconds.

128
00:05:54,920 --> 00:05:56,450
There we go, The Flying crow,

129
00:05:56,450 --> 00:05:58,520
you can see it from behind these two,

130
00:05:58,520 --> 00:05:59,570
and they killed me,

131
00:05:59,570 --> 00:06:03,770
but everything seems to be working perfectly fine.

132
00:06:03,770 --> 00:06:06,460
As you can see, we are resetting the time.

133
00:06:06,455 --> 00:06:08,075
If we scroll down.

134
00:06:08,075 --> 00:06:10,585
If you didn't completely understand what's happening,

135
00:06:10,580 --> 00:06:12,980
let me just redo it once.

136
00:06:12,980 --> 00:06:15,080
So as soon as we start a new wave,

137
00:06:15,080 --> 00:06:19,330
we start counting down until we get to the next wave.

138
00:06:19,325 --> 00:06:21,715
Then the wave countdown is reset to

139
00:06:21,710 --> 00:06:24,080
the time between waves. So an update.

140
00:06:24,080 --> 00:06:25,760
And here we are going to

141
00:06:25,760 --> 00:06:28,400
remove Time.deltaTime every single frame,

142
00:06:28,400 --> 00:06:30,640
which means that we are starting the new wave.

143
00:06:30,635 --> 00:06:33,155
Then we check, are we on the last wave?

144
00:06:33,155 --> 00:06:34,825
If we are, that means we've

145
00:06:34,820 --> 00:06:37,490
completed all the waves and we can open the door.

146
00:06:37,490 --> 00:06:39,650
Unfortunately, our enemies killed

147
00:06:39,650 --> 00:06:41,920
us before we had the chance to do so.

148
00:06:41,915 --> 00:06:44,365
But before we actually test this

149
00:06:44,360 --> 00:06:46,400
out and make sure that

150
00:06:46,400 --> 00:06:48,610
it's working this condition right here.

151
00:06:48,605 --> 00:06:49,895
Let's first of all,

152
00:06:49,895 --> 00:06:53,305
create several points from which the enemies can spawn.

153
00:06:53,300 --> 00:06:56,000
Because as you can see, we don't really like having

154
00:06:56,000 --> 00:06:57,800
all the enemies mashed up together

155
00:06:57,800 --> 00:06:59,840
and 1 and having them small.

156
00:06:59,840 --> 00:07:02,740
We want to have some kind of diversity.

157
00:07:02,735 --> 00:07:06,035
So for that, what I'm going to do is I'm going to issue

158
00:07:06,035 --> 00:07:09,535
a challenge to create spawn points for enemies.

159
00:07:09,530 --> 00:07:12,760
First of all, you need to create an array to spawn bonds.

160
00:07:12,755 --> 00:07:15,215
So this spawn points,

161
00:07:15,215 --> 00:07:18,485
this should be of type transform this array.

162
00:07:18,485 --> 00:07:20,605
Then you'll need to create the points in

163
00:07:20,600 --> 00:07:22,970
unity and add them to the inspector,

164
00:07:22,970 --> 00:07:24,710
obviously on the level manager.

165
00:07:24,710 --> 00:07:26,510
Finally, when we spawned an enemy,

166
00:07:26,510 --> 00:07:32,120
choose a random spawn points and put them there.

167
00:07:32,120 --> 00:07:35,420
So I'm going to tell you to pause the video

168
00:07:35,420 --> 00:07:36,970
because for some reason

169
00:07:36,965 --> 00:07:38,935
my punk isn't just working correctly.

170
00:07:38,930 --> 00:07:41,440
So I'll see you in just a bit.

171
00:07:41,435 --> 00:07:43,465
Hey, welcome back.

172
00:07:43,460 --> 00:07:45,790
So how did you get on with that?

173
00:07:45,785 --> 00:07:48,805
Then if I scroll up here and I create

174
00:07:48,800 --> 00:07:51,980
a serialized field of transform,

175
00:07:51,980 --> 00:07:56,630
which becomes an array of the spawn points.

176
00:07:56,630 --> 00:08:01,400
Save that. And then I scroll down to the,

177
00:08:01,400 --> 00:08:03,280
let's see what we have in here.

178
00:08:03,275 --> 00:08:07,195
Oh, so where are responding the enemies right here,

179
00:08:07,190 --> 00:08:09,100
we can simply remove the debug.

180
00:08:09,095 --> 00:08:11,065
He didn't even use it once.

181
00:08:11,060 --> 00:08:13,060
So in here, what shall we do?

182
00:08:13,055 --> 00:08:14,885
Well, we shall first of all,

183
00:08:14,885 --> 00:08:19,765
create a transform of obviously a variable of type

184
00:08:19,760 --> 00:08:21,320
transform the transform on

185
00:08:21,320 --> 00:08:25,460
the game object for this power point.

186
00:08:25,460 --> 00:08:27,320
And hopefully this will be the last video

187
00:08:27,320 --> 00:08:29,440
where I have to say the word spawn,

188
00:08:29,435 --> 00:08:31,235
spawn, whatever it is.

189
00:08:31,235 --> 00:08:33,925
So between these points,

190
00:08:33,920 --> 00:08:37,780
and in here I'm going to say random range

191
00:08:37,775 --> 00:08:42,545
between 0 and the spawn points about length.

192
00:08:42,545 --> 00:08:45,815
So we are choosing a random spawn point.

193
00:08:45,815 --> 00:08:47,545
And in here, instead of using

194
00:08:47,540 --> 00:08:49,430
the transform of the game object,

195
00:08:49,430 --> 00:08:51,380
we'll use the spawn point

196
00:08:51,380 --> 00:08:54,860
that the random spawn point that we got.

197
00:08:54,860 --> 00:08:56,930
So I believe it's pretty easy if you

198
00:08:56,930 --> 00:08:59,950
didn't understand what's happening in here.

199
00:08:59,945 --> 00:09:02,515
We created obviously the spawn points that

200
00:09:02,510 --> 00:09:04,850
we'll be adding a new unity in just a bit.

201
00:09:04,850 --> 00:09:08,480
Then when we instantiate an enemy beforehand,

202
00:09:08,480 --> 00:09:10,100
we use to immediately put him

203
00:09:10,100 --> 00:09:12,020
on the level manager game object.

204
00:09:12,020 --> 00:09:13,970
We said that we don't want to do that.

205
00:09:13,970 --> 00:09:15,890
So what we do instead is we

206
00:09:15,890 --> 00:09:17,840
use the transform box bomb point.

207
00:09:17,840 --> 00:09:19,540
We create a random one

208
00:09:19,535 --> 00:09:21,955
using the array that we have up there,

209
00:09:21,950 --> 00:09:23,840
using a random dot range from

210
00:09:23,840 --> 00:09:25,670
0 to this point, points dot length.

211
00:09:25,670 --> 00:09:26,900
And then we set the enemy,

212
00:09:26,900 --> 00:09:30,340
we instantiate them and respond point documentation.

213
00:09:30,335 --> 00:09:33,265
We save that. We go back into Unity.

214
00:09:33,260 --> 00:09:35,440
I'm going to create all this bond point

215
00:09:35,435 --> 00:09:36,865
under the level manager,

216
00:09:36,860 --> 00:09:43,840
since he's handling all of the spawning source points.

217
00:09:43,835 --> 00:09:54,535
And I'm going to create an empty spawn point, 1, 2, 3.

218
00:09:54,530 --> 00:09:56,410
So I will have three spawn points.

219
00:09:56,405 --> 00:09:59,185
Let's make the scene a bit bigger.

220
00:09:59,180 --> 00:10:01,040
And in here, Let's see,

221
00:10:01,040 --> 00:10:02,720
the first one will be here,

222
00:10:02,720 --> 00:10:04,640
the second one will be here,

223
00:10:04,640 --> 00:10:06,920
and the third one will be in here.

224
00:10:06,920 --> 00:10:10,540
So save all of that back in level manager.

225
00:10:10,535 --> 00:10:13,465
Let's see what we have in here, the spawn points.

226
00:10:13,460 --> 00:10:17,600
Let's, oops, Let's lock this down.

227
00:10:17,600 --> 00:10:21,190
Let's drag, Sorry.

228
00:10:21,185 --> 00:10:23,995
Let's drag the spawn points right here.

229
00:10:23,990 --> 00:10:27,400
We say, well, that we run the game.

230
00:10:27,395 --> 00:10:30,325
And now we should see as we are looking,

231
00:10:30,320 --> 00:10:34,280
so 321, There we go.

232
00:10:34,280 --> 00:10:35,590
So we spawned one here.

233
00:10:35,585 --> 00:10:37,855
Then after two seconds, one is up there.

234
00:10:37,850 --> 00:10:40,950
So I'm going to try to kill all of them.

235
00:10:41,740 --> 00:10:45,290
And let's see the second wave.

236
00:10:45,290 --> 00:10:47,860
That wave come down.

237
00:10:47,855 --> 00:10:52,565
Then we get one enemy which is up here,

238
00:10:52,565 --> 00:10:54,745
a second enemy which is down here.

239
00:10:54,740 --> 00:10:58,890
And then I'll try to kill them using and

240
00:10:58,885 --> 00:11:00,795
the view on the scene so I

241
00:11:00,790 --> 00:11:04,320
can catch them from a very far distance.

242
00:11:04,315 --> 00:11:06,885
So the current, the enemy dies.

243
00:11:06,880 --> 00:11:08,320
And now we have a count down.

244
00:11:08,320 --> 00:11:09,370
We can see right here that

245
00:11:09,370 --> 00:11:11,290
all the waves have been completed.

246
00:11:11,290 --> 00:11:12,970
If we double-click, where is it?

247
00:11:12,970 --> 00:11:15,040
It's right here where we are going to

248
00:11:15,040 --> 00:11:17,140
be opening the doors obviously.

249
00:11:17,140 --> 00:11:20,500
And the next video and creating also portals

250
00:11:20,500 --> 00:11:22,990
that will take us to another dimension.

251
00:11:22,990 --> 00:11:24,690
Actually it's just another level.

252
00:11:24,685 --> 00:11:26,715
But anyways, you get the point.

253
00:11:26,710 --> 00:11:28,660
Let's stop the game.

254
00:11:28,660 --> 00:11:30,120
But stop unity.

255
00:11:30,115 --> 00:11:32,505
Make sure to commit our changes.

256
00:11:32,500 --> 00:11:35,710
And I'm going to call this the, the,

257
00:11:35,710 --> 00:11:42,770
now we actually complete Waves.

258
00:11:42,770 --> 00:11:46,190
We start commit those changes.

259
00:11:46,189 --> 00:11:47,809
And I'll see you in the next one.

260
00:11:47,810 --> 00:11:48,920
And if you're enjoying,

261
00:11:48,920 --> 00:11:50,750
this is above the end of the course.

262
00:11:50,750 --> 00:11:53,770
Make sure to leave a review at helping out a lot.

263
00:11:53,765 --> 00:11:56,075
And I'll see you interested in.

