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:03,917
[MUSIC]
2
2
00:00:03,917 --> 00:00:08,083
Hello again, in this video, we're gonna do
a little bit of tidying up of our code,
3
3
00:00:08,083 --> 00:00:12,428
and we're gonna implement a death particle
effect when the attackers are smashed into
4
4
00:00:12,428 --> 00:00:13,040
oblivion.
5
5
00:00:13,040 --> 00:00:16,510
So let's start by opening
our projectile script.
6
6
00:00:16,510 --> 00:00:19,660
We can see in here that we've
got a variable for health, and
7
7
00:00:19,660 --> 00:00:21,430
we've got our health dealing damage.
8
8
00:00:21,430 --> 00:00:26,970
What I'm going to do is create another
variable that allows us to have
9
9
00:00:26,970 --> 00:00:31,110
a mechanism to say what is the health,
sorry, what is the attacker, I was looking
10
10
00:00:31,110 --> 00:00:34,540
at the one above, we've already got
the health, Rick, what are you thinking?
11
11
00:00:34,540 --> 00:00:38,550
We want to be able to
reference the attacker, and
12
12
00:00:38,550 --> 00:00:42,460
that's going to equal
otherCollider.GetComponent< >,
13
13
00:00:42,460 --> 00:00:46,350
and what do we put within
our angle brackets here?
14
14
00:00:46,350 --> 00:00:48,688
We put <Attacker>.
15
15
00:00:48,688 --> 00:00:49,738
You guessed it.
16
16
00:00:49,738 --> 00:00:50,860
Hopefully you guessed it.
17
17
00:00:50,860 --> 00:00:54,104
Yelling out at the screen randomly,
attacker.
18
18
00:00:54,104 --> 00:00:58,793
Okay, so now that we have those two
I'm gonna create an if statement
19
19
00:00:58,793 --> 00:01:03,073
here where I say if(attacker &&),
so double ampersand,
20
20
00:01:03,073 --> 00:01:07,490
that's what that thingy is,
the and sign is an ampersand.
21
21
00:01:07,490 --> 00:01:12,688
So &&, say that fast ten times, health.
22
22
00:01:12,688 --> 00:01:16,425
So that's saying that when
we're colliding with something,
23
23
00:01:16,425 --> 00:01:20,442
if it has the attacker component,
and it has the health component,
24
24
00:01:20,442 --> 00:01:23,767
if both of those are true,
then we want to do something.
25
25
00:01:23,767 --> 00:01:24,930
What is it that we wanna do?
26
26
00:01:24,930 --> 00:01:28,470
Well, we want to do our health.DealDamage.
27
27
00:01:28,470 --> 00:01:33,359
That would be the first thing, and
then also, I think what we want to do is
28
28
00:01:33,359 --> 00:01:37,298
destroy the projectile so
that it's not hanging around.
29
29
00:01:37,298 --> 00:01:39,998
You could have it that
when your enemy shoots,
30
30
00:01:39,998 --> 00:01:44,293
you have a slow projectile that goes
through and does damage to everyone,
31
31
00:01:44,293 --> 00:01:48,378
one of those like rockets that cannot
be destroyed, but for us, or for
32
32
00:01:48,378 --> 00:01:52,980
the zucchini I want it to hit and then to
go away, I think that makes more sense.
33
33
00:01:52,980 --> 00:01:57,320
So, what do we type in here if we
want to destroy the projectile?
34
34
00:01:57,320 --> 00:01:59,910
We type in Destroy(gameObject).
35
35
00:02:02,150 --> 00:02:05,026
So destroy our cell, save that up.
36
36
00:02:05,026 --> 00:02:07,412
So now, it should only be
colliding with the correct things.
37
37
00:02:07,412 --> 00:02:11,164
We probably won't see much of a change,
cuz it's not passing through any of
38
38
00:02:11,164 --> 00:02:15,208
the incorrect things, but we know that if
there was another cactus in front of it,
39
39
00:02:15,208 --> 00:02:17,219
then it wouldn't bump into that point.
40
40
00:02:17,219 --> 00:02:21,510
Boink, there we go, we hit once, and
we hit twice, and it's disappearing.
41
41
00:02:21,510 --> 00:02:22,870
Excelente!
42
42
00:02:22,870 --> 00:02:27,358
The moment of disappearing where the
attacker is killed is a little bit bland,
43
43
00:02:27,358 --> 00:02:31,647
so we're gonna spruce that up a little
bit by putting in a particle effect.
44
44
00:02:31,647 --> 00:02:36,178
And this where I've got a challenge for
you is to create a nifty
45
45
00:02:36,178 --> 00:02:40,984
particle effect and to trigger
that when the attacker is killed.
46
46
00:02:40,984 --> 00:02:42,743
So this is code that we've done before.
47
47
00:02:42,743 --> 00:02:47,114
It should be pretty straightforward for
you to find where to put that code and
48
48
00:02:47,114 --> 00:02:50,938
say, how do I trigger this particle
effect so that it happens, and
49
49
00:02:50,938 --> 00:02:55,677
if you don't wanna create a particle
effect, then I've got one that I'm using.
50
50
00:02:55,677 --> 00:02:59,213
Just one of our other projects in
this course that I can give to you as
51
51
00:02:59,213 --> 00:03:01,243
downloadable against this lecture.
52
52
00:03:01,243 --> 00:03:06,527
So you can grab that, if you like,
as a asset pack or you can make your own.
53
53
00:03:06,527 --> 00:03:08,320
So jump in, take on that challenge.
54
54
00:03:08,320 --> 00:03:10,211
I'll see you back here when
you've given it your best shot.
55
55
00:03:12,490 --> 00:03:14,474
Okay, let's go and grab that asset.
56
56
00:03:14,474 --> 00:03:17,110
So I've got ExplosionVFX.
57
57
00:03:17,110 --> 00:03:21,977
When I drag it in anywhere into my Assets
folder it asks me whether I'd like
58
58
00:03:21,977 --> 00:03:22,768
to import.
59
59
00:03:22,768 --> 00:03:26,038
Yes, I import, and it brings in
the folder structure as well, so
60
60
00:03:26,038 --> 00:03:29,010
I've got this VFX folder down
here with the Explosion VFX,
61
61
00:03:29,010 --> 00:03:32,890
[LAUGH] which you might recognize from
one of the other sections of the course.
62
62
00:03:32,890 --> 00:03:33,809
I've just gone and grabbed it.
63
63
00:03:33,809 --> 00:03:37,634
You can take plenty of time to
finesse with your particle effect but
64
64
00:03:37,634 --> 00:03:41,030
I'm not gonna go through
that in too much detail.
65
65
00:03:41,030 --> 00:03:44,544
I just wanted to get something
that we could use for now.
66
66
00:03:44,544 --> 00:03:45,941
Let's just have a look,
make sure it works.
67
67
00:03:45,941 --> 00:03:46,624
Boink, there we go.
68
68
00:03:46,624 --> 00:03:48,720
It's kind of stars going a bit crazy.
69
69
00:03:48,720 --> 00:03:49,559
Good enough.
70
70
00:03:49,559 --> 00:03:51,042
Job done.
71
71
00:03:51,042 --> 00:03:58,120
Okay, so
let's go over into our health script.
72
72
00:03:58,120 --> 00:04:02,200
Above Destroy,
we need a notion of calling a method where
73
73
00:04:02,200 --> 00:04:07,196
we're going to say TriggerDeathVFX().
74
74
00:04:07,196 --> 00:04:11,694
Okay, we wanna trigger the VFX and
then we want to destroy it ourselves,
75
75
00:04:11,694 --> 00:04:14,571
in this case it's destroying the lizard,
and
76
76
00:04:14,571 --> 00:04:18,578
we want to make sure that
the DeathVFX isn't destroyed as well.
77
77
00:04:18,578 --> 00:04:20,410
So that's a little bit trickier.
78
78
00:04:20,410 --> 00:04:25,510
This is why we need to instantiate,
rather than just playing a VFX,
79
79
00:04:25,510 --> 00:04:29,990
rather than just playing a particle effect
on, where's one of my lizards here?
80
80
00:04:29,990 --> 00:04:34,280
Prefab > Lizard, drag them into
the scene so we put him there.
81
81
00:04:34,280 --> 00:04:39,420
So we could have as a child, we could
have a particle effect under the lizard.
82
82
00:04:39,420 --> 00:04:42,770
But then when we destroy the lizard,
we're also destroying the child,
83
83
00:04:42,770 --> 00:04:44,610
the particle effect underneath that.
84
84
00:04:44,610 --> 00:04:52,633
So we're create ourselves
a private void TriggerDeathVFX.
85
85
00:04:52,633 --> 00:04:53,783
What do we want to do in here?
86
86
00:04:53,783 --> 00:04:57,931
Well, first of all I'm gonna say, if we
don't have any VFX, then just return,
87
87
00:04:57,931 --> 00:05:00,433
just in case we forget to
put something on there,
88
88
00:05:00,433 --> 00:05:03,240
we don't want something to
break where it says, hey,
89
89
00:05:03,240 --> 00:05:06,803
trigger a particular particle effect and
we've kind of forgotten.
90
90
00:05:06,803 --> 00:05:09,026
I know that you would never
forget to do that, but
91
91
00:05:09,026 --> 00:05:10,825
I forget to do these things sometimes.
92
92
00:05:10,825 --> 00:05:13,810
So say, if there is no,
what are we going to call this?
93
93
00:05:13,810 --> 00:05:18,482
We'll call this deathvfx, we're going
to make that variable in a moment,
94
94
00:05:18,482 --> 00:05:19,655
then just return.
95
95
00:05:19,655 --> 00:05:22,800
Just go about your business,
don't worry, don'tdon't stress about it.
96
96
00:05:22,800 --> 00:05:24,566
Unity, everything will be fine.
97
97
00:05:24,566 --> 00:05:28,269
So let's go and
serialize ourselves a variable,
98
98
00:05:28,269 --> 00:05:32,591
[SerializeField] GameObject,
cuz we want to be able to
99
99
00:05:32,591 --> 00:05:37,371
reference it as a GameObject in a moment,
and it's a deathVFX.
100
100
00:05:37,371 --> 00:05:42,239
Okay, so now we have this notion of
we're gonna drag in our deathVFX,
101
101
00:05:42,239 --> 00:05:46,390
that we just brought in,
the explosion thing I had before.
102
102
00:05:46,390 --> 00:05:49,685
If it doesn't exist, if you don't have
one of these then don't worry about it,
103
103
00:05:49,685 --> 00:05:50,369
just return it.
104
104
00:05:50,369 --> 00:05:51,860
Otherwise, what are we gonna do?
105
105
00:05:51,860 --> 00:05:55,324
Well, we'll start off just by saying,
instantiate.
106
106
00:05:55,324 --> 00:05:58,590
Instantiate, what do we need to do here?
107
107
00:05:58,590 --> 00:06:00,660
Well, we're gonna instantiate(deathVFX, ).
108
108
00:06:00,660 --> 00:06:02,970
We've done this a bunch of
times when instantiating.
109
109
00:06:02,970 --> 00:06:04,717
It should be pretty natural by now.
110
110
00:06:04,717 --> 00:06:05,790
And then where is it?
111
111
00:06:05,790 --> 00:06:12,630
It's transform.position.
112
112
00:06:12,630 --> 00:06:13,772
Had to think for a moment there.
113
113
00:06:13,772 --> 00:06:19,511
And then we can do transform.rotation,
or we can do the quotidian.identity.
114
114
00:06:19,511 --> 00:06:24,184
I just like doing transform.rotation
when it doesn't really matter what our
115
115
00:06:24,184 --> 00:06:28,926
rotation is, we're just putting it in
there so that this instantiates happy,
116
116
00:06:28,926 --> 00:06:32,350
it's not confused saying
what's the rotation, Rick?
117
117
00:06:32,350 --> 00:06:34,204
Okay, let's see how this goes,
if this works.
118
118
00:06:34,204 --> 00:06:36,540
Jump back over,
we need to create that reference.
119
119
00:06:36,540 --> 00:06:43,230
So on Lizard, we should now see,
on our health script,
120
120
00:06:43,230 --> 00:06:47,590
we can see it's looking for
deathVFX whereas my VFX,
121
121
00:06:47,590 --> 00:06:52,570
I will grab Explosion VFX,
drag it on over into there.
122
122
00:06:52,570 --> 00:06:57,153
Click on play just to make
sure that this works.
123
123
00:06:57,153 --> 00:07:03,004
He jumps out, shoot, bang, and
one more time, shoot, bang, [SOUND].
124
124
00:07:03,004 --> 00:07:05,084
Okay, we didn't get a VFX, why is that?
125
125
00:07:05,084 --> 00:07:08,362
Well let's go to our Explosion VFX,
it's probably,
126
126
00:07:08,362 --> 00:07:12,920
if we scroll down down down to the
renderer, we can see, if we look closely,
127
127
00:07:12,920 --> 00:07:16,650
the Order in Layer is 0, so
we've gone through that before.
128
128
00:07:16,650 --> 00:07:19,281
I'll put this at 6 so
it sits over the top of everything.
129
129
00:07:19,281 --> 00:07:24,620
That's right on the prefab, so that
should be applied to what we're calling.
130
130
00:07:24,620 --> 00:07:28,387
Okay, we'll try this again.
131
131
00:07:28,387 --> 00:07:29,510
Okay, it's jumps out.
132
132
00:07:29,510 --> 00:07:30,397
[SOUND] You know what I'm gonna do?
133
133
00:07:30,397 --> 00:07:31,988
This has [LAUGH] been bugging me for
awhile.
134
134
00:07:31,988 --> 00:07:33,110
I don't know, I haven't done this.
135
135
00:07:33,110 --> 00:07:34,620
I'm gonna click on my lizard.
136
136
00:07:34,620 --> 00:07:37,940
Go down, instead of 100 health,
I'm gonna give you 30 health, so
137
137
00:07:37,940 --> 00:07:39,960
you get shot and killed.
138
138
00:07:39,960 --> 00:07:43,170
I'm gonna click apply,
shot and killed with one shot.
139
139
00:07:43,170 --> 00:07:47,820
Now if we want to see how it works with
multiple shots then we'll put that back up
140
140
00:07:47,820 --> 00:07:49,100
again, but for now.
141
141
00:07:49,100 --> 00:07:53,203
Kaboom, there we go, nice, and
it created a particle effect.
142
142
00:07:53,203 --> 00:07:54,450
Let's have a look in here.
143
143
00:07:54,450 --> 00:07:57,421
We've got this Explosion VFX,
now that's gonna
144
144
00:07:57,421 --> 00:08:02,102
stick around forever if we don't take
care of it, so let's go take care of it.
145
145
00:08:02,102 --> 00:08:03,100
How do we take care of it?
146
146
00:08:03,100 --> 00:08:05,808
Well, we need to destroy
the particle effect and
147
147
00:08:05,808 --> 00:08:07,797
this is why we're instantiating.
148
148
00:08:07,797 --> 00:08:10,989
Sorry, we're instantiating because
the lizard gets destroyed,
149
149
00:08:10,989 --> 00:08:14,573
and this creates this whole new game
object here, but we need a handle to it,
150
150
00:08:14,573 --> 00:08:16,760
we need a way of referring
to this game object.
151
151
00:08:16,760 --> 00:08:23,050
So we'll create ourselves a GameObject
type called deathVFXObject,
152
152
00:08:23,050 --> 00:08:27,780
and that's equal to what
we've just instantiated.
153
153
00:08:27,780 --> 00:08:33,958
So now we have this notion
of there's a deathVFXObject,
154
154
00:08:33,958 --> 00:08:40,395
so on our next line we can
say Destroy(deathVFXObject),
155
155
00:08:40,395 --> 00:08:45,560
and we have the option of
saying after how long.
156
156
00:08:45,560 --> 00:08:48,170
We don't wanna destroy it straight away,
because we need to actually see
157
157
00:08:48,170 --> 00:08:50,980
the particle effects, so
we'll say after a second.
158
158
00:08:50,980 --> 00:08:54,280
This is a little bit of a magic number
in here, but I'm okay with that.
159
159
00:08:54,280 --> 00:08:59,470
We could put it to 10 and
be super safe, but I'll leave it at 1.
160
160
00:08:59,470 --> 00:09:03,380
I'm pretty sure my particle
effect is gonna be come and
161
161
00:09:03,380 --> 00:09:06,300
gone in one second no problem.
162
162
00:09:06,300 --> 00:09:10,291
So we'll make sure all that works and
is hunky dory.
163
163
00:09:10,291 --> 00:09:14,893
Click on play, watch our hierarchy,
lizard's being spawned, blump,
164
164
00:09:14,893 --> 00:09:17,877
explosion, and
then the explosion went away.
165
165
00:09:17,877 --> 00:09:23,577
Now, if you look at it closely,
I think, here we go, when it hits,
166
166
00:09:23,577 --> 00:09:29,880
when it strikes, boink, the particle
effect is a little bit to the right.
167
167
00:09:29,880 --> 00:09:31,387
It looks a little bit off.
168
168
00:09:31,387 --> 00:09:34,479
It's all going pretty quick so
you don't really notice it, but
169
169
00:09:34,479 --> 00:09:36,150
there's a few ways to solve this.
170
170
00:09:36,150 --> 00:09:39,700
For now, I'm going to be a little bit
cheeky, okay, and for the [LAUGH]
171
171
00:09:39,700 --> 00:09:42,370
experienced programmers out there you're
gonna be like,what are you doing?
172
172
00:09:42,370 --> 00:09:45,130
I'm gonna be a little bit cheeky and
173
173
00:09:45,130 --> 00:09:50,190
show you how I will move the particle
effect as opposed to trying to
174
174
00:09:50,190 --> 00:09:55,078
reposition it on the lizard, or
on the lizard's pivot point.
175
175
00:09:55,078 --> 00:09:57,530
So you see the pivot point there.
176
176
00:09:57,530 --> 00:10:01,041
Instead of trying to change where we
instantiate it I'm just gonna change
177
177
00:10:01,041 --> 00:10:02,694
the particle effect a little bit.
178
178
00:10:02,694 --> 00:10:07,634
So forgive me on this that it's not
perfect, but sometimes I think it's good
179
179
00:10:07,634 --> 00:10:11,130
to do these little tweaks so
that we can keep on moving.
180
180
00:10:11,130 --> 00:10:16,790
So let's find our VFX > Explosion VFX,
Drag one of those into the scene.
181
181
00:10:16,790 --> 00:10:19,303
You can see here is the particle effect.
182
182
00:10:19,303 --> 00:10:22,144
If we zoom in,
this little symbol is showing it, and
183
183
00:10:22,144 --> 00:10:25,450
that represents where the middle
of the particle effect is.
184
184
00:10:25,450 --> 00:10:31,050
If I scroll down on my particle effect,
and find let's see, Shape, and on Shape,
185
185
00:10:31,050 --> 00:10:35,850
I've got position on my X coordinate,
if I drag that over a little bit,
186
186
00:10:35,850 --> 00:10:40,490
you can see that this is where the origin,
or the basis of the particle
187
187
00:10:40,490 --> 00:10:45,131
effect is gonna be, and this is
where spawning the actual particle.
188
188
00:10:45,131 --> 00:10:47,860
So, if I click play,
that's a little bit to the left.
189
189
00:10:47,860 --> 00:10:51,840
I know this is a little bit hacky, but
I think this is a great quick solution to
190
190
00:10:51,840 --> 00:10:54,960
the fact that it's not quite lining
up the way we want it to line up.
191
191
00:10:54,960 --> 00:10:57,390
Instead of having to go and
mess around with the lizard,
192
192
00:10:57,390 --> 00:10:59,250
and the lizards animation
we can do that later on.
193
193
00:10:59,250 --> 00:11:01,610
We'll tidy that later on,
but this is just a quickie.
194
194
00:11:01,610 --> 00:11:04,463
We'll apply this back to the prefab.
195
195
00:11:04,463 --> 00:11:06,660
Just remove that from our scene.
196
196
00:11:06,660 --> 00:11:11,016
Let's have our lizard come walking in,
walk, walk, walk, walk, and boink,
197
197
00:11:11,016 --> 00:11:14,880
that looked like it landed right
over the top, so that's pretty good.
198
198
00:11:14,880 --> 00:11:16,773
Okay, as I said,
it's not the best particle effect.
199
199
00:11:16,773 --> 00:11:20,052
Hopefully you've done something a little
bit sharper than that, and also,
200
200
00:11:20,052 --> 00:11:22,876
if you've found that it's not
spawning quite in the right place,
201
201
00:11:22,876 --> 00:11:26,166
I've given you a bit of a hint there on
how you can tweak your particle effect.
202
202
00:11:26,166 --> 00:11:29,792
Okay, so that's all I wanted to do in
this video, just tidying thing up and
203
203
00:11:29,792 --> 00:11:32,455
getting a little bit of
a particle effect triggering.
204
204
00:11:32,455 --> 00:11:37,234
In the next video, we'll do,
I'm not sure yet, something cool [LAUGH].
205
205
00:11:37,234 --> 00:11:38,940
I'll see you in the next video.
20884
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.