Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
1
00:00:00,000 --> 00:00:04,105
[MUSIC]
2
2
00:00:04,105 --> 00:00:07,438
In this video,
we're gonna shift the movement speed and
3
3
00:00:07,438 --> 00:00:11,395
the wave configuration that has its
waypoints in it off the enemy and
4
4
00:00:11,395 --> 00:00:16,250
have all that information within the enemy
spawner and the waves themselves.
5
5
00:00:16,250 --> 00:00:20,490
So the enemy is clever in knowing what
path to follow, without us having to go
6
6
00:00:20,490 --> 00:00:24,540
and link all of those things onto
a particular enemy prefab itself.
7
7
00:00:24,540 --> 00:00:25,230
Why do this?
8
8
00:00:25,230 --> 00:00:26,010
Well this is so
9
9
00:00:26,010 --> 00:00:29,520
we can have this particular enemy
come in at different speeds and
10
10
00:00:29,520 --> 00:00:33,944
go on different paths and not always have
to go on the same path every single time.
11
11
00:00:33,944 --> 00:00:36,100
I think that's gonna give
us a lot more creativity.
12
12
00:00:36,100 --> 00:00:41,200
So what we'll start off with is jumping
over into the enemy pathing script.
13
13
00:00:41,200 --> 00:00:43,130
We haven't used that for a lecture or two.
14
14
00:00:43,130 --> 00:00:45,078
Enemy pathing is what
we will be looking at.
15
15
00:00:45,078 --> 00:00:48,952
And I'm gonna start here by highlighting
the fact that we need to or
16
16
00:00:48,952 --> 00:00:51,592
we can remove some of
our SerializedFields.
17
17
00:00:51,592 --> 00:00:54,412
So we still need to have
our WaveConfig variable but
18
18
00:00:54,412 --> 00:00:56,452
we don't need access to it anymore.
19
19
00:00:56,452 --> 00:00:59,536
So that will no longer show up
on the enemy in the inspector.
20
20
00:00:59,536 --> 00:01:02,217
And likewise, this float moveSpeed,
21
21
00:01:02,217 --> 00:01:07,100
we're going to remove completely and
replace it with something else.
22
22
00:01:07,100 --> 00:01:08,240
And what'll we replace it with?
23
23
00:01:08,240 --> 00:01:10,270
Well, here's a little challenge for you.
24
24
00:01:10,270 --> 00:01:14,560
I want you to get the speed for
the enemies from the WaveConfig data
25
25
00:01:14,560 --> 00:01:17,248
instead of using moveSpeed,
which I just deleted.
26
26
00:01:17,248 --> 00:01:21,220
So find where moveSpeed is,
or in my case was, and
27
27
00:01:21,220 --> 00:01:27,440
instead of using that moveSpeed variable,
get the information from the WaveConfig.
28
28
00:01:27,440 --> 00:01:29,010
Okay, so there's your challenge.
29
29
00:01:29,010 --> 00:01:30,558
Pause the video and jump into that now.
30
30
00:01:33,073 --> 00:01:33,680
Welcome back.
31
31
00:01:33,680 --> 00:01:35,460
Hopefully you are taking
on the challenges.
32
32
00:01:35,460 --> 00:01:39,110
They are the absolute number
one best way to learn.
33
33
00:01:39,110 --> 00:01:41,864
That's why you're taking this course and
34
34
00:01:41,864 --> 00:01:45,315
not just watching along
some random YouTube videos.
35
35
00:01:45,315 --> 00:01:48,782
This is the process of learning cuz
you're taking on the challenges,
36
36
00:01:48,782 --> 00:01:50,321
I hope as the best way to learn.
37
37
00:01:50,321 --> 00:01:53,849
So you can see now cuz I've delayed
moveSpeed, got the squiggly red line.
38
38
00:01:53,849 --> 00:02:00,170
Instead of moveSpeed, we need to access
our waveConfig., what's its gonna be?
39
39
00:02:00,170 --> 00:02:03,380
GetMoveSpeed, it's highlighted already,
GetMoveSpeed and
40
40
00:02:03,380 --> 00:02:06,300
then we need our parentheses
cuz it is a method.
41
41
00:02:06,300 --> 00:02:11,324
So, now it's going to go into our
waveConfig, get the particular
42
42
00:02:11,324 --> 00:02:17,076
movement speed that we've set for
this wave and then use that for our enemy.
43
43
00:02:17,076 --> 00:02:21,423
Now, in terms of the wave configuration,
to know which wave to follow, so
44
44
00:02:21,423 --> 00:02:24,117
that we don't have to
connect it up manually.
45
45
00:02:24,117 --> 00:02:28,738
We're going to add ourselves a new
public method that, in here,
46
46
00:02:28,738 --> 00:02:33,290
has the information that we feed
into our particular waypoint.
47
47
00:02:33,290 --> 00:02:37,669
So you can see this is following our path,
we need to know which path to follow.
48
48
00:02:37,669 --> 00:02:42,168
And to do that, we want something else to
be telling us that from another script.
49
49
00:02:42,168 --> 00:02:46,198
So what we'll do is we'll create
ourselves a public method,
50
50
00:02:46,198 --> 00:02:50,325
say public void, set,
we'll call this SetWaveConfig.
51
51
00:02:50,325 --> 00:02:53,432
Now we've been doing, I'm just
going to leave that midway through,
52
52
00:02:53,432 --> 00:02:55,075
just remind you in our waveConfigs.
53
53
00:02:55,075 --> 00:02:59,554
We've been doing these get methods
where we say hey, return me a value and
54
54
00:02:59,554 --> 00:03:02,961
that value we've established
in our waveConfig file.
55
55
00:03:02,961 --> 00:03:07,528
In this instance, we're gonna say hey,
set the particular thing for me.
56
56
00:03:07,528 --> 00:03:12,042
So it's a public method that
something else can be feeding into
57
57
00:03:12,042 --> 00:03:13,922
a value into this script.
58
58
00:03:13,922 --> 00:03:16,282
So it's a set method, if you will.
59
59
00:03:16,282 --> 00:03:20,332
And in here,
we put inside the parentheses, what is it?
60
60
00:03:20,332 --> 00:03:23,789
What's the information that we
need to have when this is called?
61
61
00:03:23,789 --> 00:03:28,634
So as soon as we have parameters in
our signature here, SetWaveConfig.
62
62
00:03:28,634 --> 00:03:33,236
As soon as we put something in here and
I'm gonna put in waveConfig, so it's of
63
63
00:03:33,236 --> 00:03:37,862
type waveConfig, we'll call it waveConfig
cuz that's what we need to know.
64
64
00:03:37,862 --> 00:03:42,033
We want to know what is the waveConfig
that we should be following for
65
65
00:03:42,033 --> 00:03:44,608
this current enemy on this current path.
66
66
00:03:44,608 --> 00:03:48,862
And so,
when anything calls this public method,
67
67
00:03:48,862 --> 00:03:52,724
it has to also tell us
what the waveConfig is.
68
68
00:03:52,724 --> 00:03:58,578
If it doesn't do that, if in another
script if we just say SetWaveConfig and
69
69
00:03:58,578 --> 00:04:01,601
open close parentheses, semicolon.
70
70
00:04:01,601 --> 00:04:02,771
If we just do that,
71
71
00:04:02,771 --> 00:04:07,600
then we're going to get an error because
we've constructed our method here,
72
72
00:04:07,600 --> 00:04:12,600
saying you have to give me, thou shall
give me the waveConfig information.
73
73
00:04:12,600 --> 00:04:15,750
So when we are calling our method from
another place, which we'll do in just
74
74
00:04:15,750 --> 00:04:19,740
a moment, we actually have to put
in there what the waveConfig is.
75
75
00:04:19,740 --> 00:04:24,160
So that this waveConfig
is getting fed into here.
76
76
00:04:24,160 --> 00:04:27,050
So we know that this
becomes a container for
77
77
00:04:27,050 --> 00:04:31,410
whatever it was that this
waveConfig is in the other file.
78
78
00:04:31,410 --> 00:04:34,100
Okay, just going nice and slow on
that because I know it puzzled me for
79
79
00:04:34,100 --> 00:04:37,760
a long time in terms of what's
this stuff inside the brackets?
80
80
00:04:37,760 --> 00:04:42,230
Well the main thing to know is that
we are wanting information from
81
81
00:04:42,230 --> 00:04:43,280
whoever called this.
82
82
00:04:43,280 --> 00:04:46,500
Now, this part is going to blow your
mind if you're not paying attention.
83
83
00:04:46,500 --> 00:04:48,880
So, get ready to pay some attention.
84
84
00:04:48,880 --> 00:04:54,397
What we need to do here is to set
the waveConfig variable in this class,
85
85
00:04:54,397 --> 00:04:58,336
which is up here,
we've set this as waveConfig.
86
86
00:04:58,336 --> 00:05:01,896
And we're using this waveConfig variable
in a number of spots down here to say
87
87
00:05:01,896 --> 00:05:03,334
okay, what I'm I following?
88
88
00:05:03,334 --> 00:05:06,927
What I'm I heading towards
in terms of my waveConfig?
89
89
00:05:06,927 --> 00:05:12,445
But then we also this concept of the
waveConfig local variable to this method,
90
90
00:05:12,445 --> 00:05:14,630
which is being passed back in.
91
91
00:05:14,630 --> 00:05:19,180
Now we could call this something
different like waveConfigToSet.
92
92
00:05:19,180 --> 00:05:21,770
We could do that but
at the end of the day, it's a waveConfig.
93
93
00:05:21,770 --> 00:05:27,048
So we're gonna use the same word,
waveConfig but it has two slightly
94
94
00:05:27,048 --> 00:05:32,056
different meanings or
they're slightly different variables.
95
95
00:05:32,056 --> 00:05:37,515
So what I'm going to say
in here is this.Wave,
96
96
00:05:37,515 --> 00:05:43,799
sorry, little w,
waveConfig = waveConfig, okay?
97
97
00:05:43,799 --> 00:05:45,920
And again, I'm gonna go slow on this so
it's super duper clear,
98
98
00:05:45,920 --> 00:05:47,362
I'll just get rid of
some of my white space.
99
99
00:05:47,362 --> 00:05:51,043
Super clear,
when we say this in front of waveConfig,
100
100
00:05:51,043 --> 00:05:55,374
we're referring to this in the class,
the instance variable.
101
101
00:05:55,374 --> 00:06:00,019
So at the top here, this variable can
be used throughout our entire class,
102
102
00:06:00,019 --> 00:06:01,432
our entire instance.
103
103
00:06:01,432 --> 00:06:06,358
Therefore, it is this, this is the thing
that we're on, this is the script,
104
104
00:06:06,358 --> 00:06:08,085
the class, the document.
105
105
00:06:08,085 --> 00:06:11,186
When we use this,
referring to this whole thing.
106
106
00:06:11,186 --> 00:06:16,492
So this.waveConfig is referring
to this particular waveConfig and
107
107
00:06:16,492 --> 00:06:21,614
then it equals the waveConfig that
we receive when something calls
108
108
00:06:21,614 --> 00:06:26,744
the public method SetWaveConfig and
passes to us the waveConfig.
109
109
00:06:26,744 --> 00:06:29,566
Okay, I'm gonna save up this and
then go to the spot where we are.
110
110
00:06:29,566 --> 00:06:32,133
I'm going to call the waveConfig and
I'll show you what I mean.
111
111
00:06:32,133 --> 00:06:37,670
So over into EnemySpawner,
instead of just instantiating,
112
112
00:06:37,670 --> 00:06:42,779
we're gonna create a new variable,
which we'll say var
113
113
00:06:42,779 --> 00:06:48,750
newEnemy = Instantiate and
then what and where and the rotation.
114
114
00:06:48,750 --> 00:06:52,861
So now we're storing this new enemy
each time we create an enemy,
115
115
00:06:52,861 --> 00:06:54,216
it will be newEnemy.
116
116
00:06:54,216 --> 00:06:57,494
And that allows us to grab the component,
so
117
117
00:06:57,494 --> 00:07:02,457
if we give ourselves a line between
the end of our instantiation and
118
118
00:07:02,457 --> 00:07:06,140
before the yield, we'll type in newEnemy.
119
119
00:07:06,140 --> 00:07:09,370
So, we're referring to this
newEnemy we've just created dot.
120
120
00:07:09,370 --> 00:07:11,867
So there's something within
the newEnemy that we're looking for.
121
121
00:07:11,867 --> 00:07:16,744
GetComponent, With our angle braces cuz
122
122
00:07:16,744 --> 00:07:20,823
when we create this game object,
we're looking for a particular thing.
123
123
00:07:20,823 --> 00:07:24,097
The component we're looking for
is the enemy pathing.
124
124
00:07:24,097 --> 00:07:25,744
So that's the enemy pathing script.
125
125
00:07:25,744 --> 00:07:29,674
Then when we have a look at our enemy, you
can see, if I find an enemy, you can see
126
126
00:07:29,674 --> 00:07:33,550
it has a script and the script is also
a component that's sitting on the enemy,
127
127
00:07:33,550 --> 00:07:36,045
that's how we can access
it using getComponent.
128
128
00:07:36,045 --> 00:07:39,087
Then we need to add our parentheses after
129
129
00:07:39,087 --> 00:07:43,209
enemy pathing.SetWaveConfig
that we just created.
130
130
00:07:43,209 --> 00:07:44,696
And what do we need to feed into that?
131
131
00:07:44,696 --> 00:07:47,665
We need to feed in,
you guessed it, the waveConfig.
132
132
00:07:47,665 --> 00:07:50,229
And which wave and
then put a semicolon on the end.
133
133
00:07:50,229 --> 00:07:51,944
Which waveConfig they're referring to?
134
134
00:07:51,944 --> 00:07:55,713
It's the waveConfig that's locally
within the SpawnAllEnemies.
135
135
00:07:55,713 --> 00:08:00,069
So it knows, this is the particular
wave that I'm referring to.
136
136
00:08:00,069 --> 00:08:04,014
And then when we call this method,
it's going to pass in this waveConfig
137
137
00:08:04,014 --> 00:08:08,230
that we're getting from here into our
enemy pathing because it required us.
138
138
00:08:08,230 --> 00:08:12,391
It said, you have to give me
this information when you
139
139
00:08:12,391 --> 00:08:17,290
are calling SetWaveConfig and
I'm gonna use this information
140
140
00:08:17,290 --> 00:08:21,367
to define my own waveConfig
in my particular class.
141
141
00:08:21,367 --> 00:08:25,956
Okay, let's save all of these, I've jumped
back over into Unity, click on our enemy.
142
142
00:08:25,956 --> 00:08:27,845
Those extra bits and
pieces are no longer there.
143
143
00:08:27,845 --> 00:08:29,054
Let's go find our waves.
144
144
00:08:29,054 --> 00:08:30,781
Click on Wave 1.
145
145
00:08:30,781 --> 00:08:35,572
I'm gonna change the movement speed
to 8 and make sure this works.
146
146
00:08:35,572 --> 00:08:36,317
Path zero, which one's path zero?
147
147
00:08:36,317 --> 00:08:37,704
That's that one.
148
148
00:08:37,704 --> 00:08:40,413
Okay, I'll change it to path one for now,
149
149
00:08:40,413 --> 00:08:45,010
on wave one just to check that
it works and then click on play.
150
150
00:08:45,010 --> 00:08:47,215
We should have it coming
from left to right, is it?
151
151
00:08:47,215 --> 00:08:48,010
Or right to left?
152
152
00:08:48,010 --> 00:08:49,364
Okay and they're going nice and fast,
153
153
00:08:49,364 --> 00:08:51,940
it looks like they're definitely
going eight amount of speed.
154
154
00:08:51,940 --> 00:08:55,722
If I was to just change it over to
the other path, to check this all works,
155
155
00:08:55,722 --> 00:09:00,064
path zero and make the movement speed,
I don't know, 20 just to be ridiculous.
156
156
00:09:00,064 --> 00:09:06,620
Click on play and it should go zing and
spawn, one, two, three, four, five.
157
157
00:09:06,620 --> 00:09:07,710
Excellent, okay, there we go.
158
158
00:09:07,710 --> 00:09:12,480
So now we've got more of our
information stored on our wave.
159
159
00:09:12,480 --> 00:09:15,750
The value in doing this is now we
can create waves where we mix and
160
160
00:09:15,750 --> 00:09:17,530
match the speed, the paths and
161
161
00:09:17,530 --> 00:09:21,570
the enemies to give us a whole
ton of variation within our game.
162
162
00:09:21,570 --> 00:09:22,480
So, great work.
163
163
00:09:22,480 --> 00:09:25,580
In the next video, we'll continue
on with spawning more waves.
16730
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.