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,723
[SOUND]
>> Hello again,
2
2
00:00:04,723 --> 00:00:07,897
in this video we are evolving our
attackers so that when they bump into
3
3
00:00:07,897 --> 00:00:11,480
a defender and, here we go,
something, don't shoot, there we go.
4
4
00:00:11,480 --> 00:00:14,520
They start to switch animation
state to attacking and
5
5
00:00:14,520 --> 00:00:15,790
start to attack the defenders.
6
6
00:00:15,790 --> 00:00:17,150
So let's jump in and get started.
7
7
00:00:17,150 --> 00:00:18,700
Right, let's have a look
at what we have got.
8
8
00:00:18,700 --> 00:00:23,120
In our attackers, we have got one attacker
which is the lizard and looking at it now,
9
9
00:00:23,120 --> 00:00:24,872
the collision is in
slightly the wrong spot.
10
10
00:00:24,872 --> 00:00:29,045
So I'm gonna change the collision,
clicking on Edit Collider, just move it up
11
11
00:00:29,045 --> 00:00:32,928
so it's actually over the lizard and
not just hanging out in a weird spot.
12
12
00:00:32,928 --> 00:00:34,912
There we go, apply that back to be PreFab.
13
13
00:00:34,912 --> 00:00:36,380
All right, now I've got one lizard.
14
14
00:00:36,380 --> 00:00:37,370
What else do we need?
15
15
00:00:37,370 --> 00:00:38,470
Who else do we need in our game?
16
16
00:00:38,470 --> 00:00:39,292
Well, let's have a look at that.
17
17
00:00:39,292 --> 00:00:43,897
I am gonna have in my execution of this
game a lizard, a fox, a weird jelly or
18
18
00:00:43,897 --> 00:00:48,209
jello kind of dude, and this guy
who's called Jabba for some reason,
19
19
00:00:48,209 --> 00:00:51,010
I guess because he looks
like Jabba the Hutt.
20
20
00:00:51,010 --> 00:00:52,010
And well done, Rick.
21
21
00:00:52,010 --> 00:00:52,559
Good work.
22
22
00:00:52,559 --> 00:00:56,350
[LAUGH] I'm just like Sherlock Holmes for
figuring that out, aren't I?
23
23
00:00:56,350 --> 00:01:00,180
Okay, so I've got speed, attack,
health, and a special ability.
24
24
00:01:00,180 --> 00:01:03,390
This speed and attack and health,
I'm not gonna go into too much detail.
25
25
00:01:03,390 --> 00:01:06,360
It's kind of regular guy, fast guy.
26
26
00:01:06,360 --> 00:01:08,030
And then this guy's
a little bit different, and
27
27
00:01:08,030 --> 00:01:09,630
that guy's a little bit different as well.
28
28
00:01:09,630 --> 00:01:11,770
In terms of the special,
the lizard doesn't have a special,
29
29
00:01:11,770 --> 00:01:13,550
he just runs up and hits things.
30
30
00:01:13,550 --> 00:01:16,820
The fox is gonna jump
over particular things,
31
31
00:01:16,820 --> 00:01:19,970
specifically the gravestone or the,
is that what we're calling it?
32
32
00:01:19,970 --> 00:01:20,820
Gravestone, yes.
33
33
00:01:20,820 --> 00:01:23,390
That we put into our game
doesn't stop the fox.
34
34
00:01:23,390 --> 00:01:28,430
The Jello guy, gotta make myself
North Americanized, is Ghosting.
35
35
00:01:28,430 --> 00:01:31,210
So he doesn't bump into anything.
36
36
00:01:31,210 --> 00:01:34,480
Just goes walk, walk, walk, walk,
walk, right through everything.
37
37
00:01:34,480 --> 00:01:37,320
And then this big old
guy goes really slowly.
38
38
00:01:37,320 --> 00:01:39,520
Classic kind of tank
dude smashes into stuff.
39
39
00:01:39,520 --> 00:01:40,780
And I'll leave a question mark here.
40
40
00:01:40,780 --> 00:01:43,700
This is gonna be something that at
some point you can go ahead and
41
41
00:01:43,700 --> 00:01:47,320
make a cool special move for
the Java character.
42
42
00:01:47,320 --> 00:01:49,850
Now what do we need to do in what spot?
43
43
00:01:49,850 --> 00:01:52,120
We've gone our three scripts
I'm gonna be referring to.
44
44
00:01:52,120 --> 00:01:55,120
Attacker and then Lizard script or
45
45
00:01:55,120 --> 00:01:58,620
Fox scripts is gonna be specific
to the individual attackers.
46
46
00:01:58,620 --> 00:02:03,080
So each character, each attacker will
have its own script and then health.
47
47
00:02:03,080 --> 00:02:05,890
With an attacker, we want it to move left,
we've done that, set speed,
48
48
00:02:05,890 --> 00:02:09,890
done that, update animation state, we'll
do that, and attack a specific target,
49
49
00:02:09,890 --> 00:02:10,940
we'll do that as well.
50
50
00:02:10,940 --> 00:02:14,510
What I mean by specific is we want
our attackers to only be attacking
51
51
00:02:14,510 --> 00:02:16,700
one defender at once.
52
52
00:02:16,700 --> 00:02:20,658
And then on, say, the lizard script,
or on the Fox script, or
53
53
00:02:20,658 --> 00:02:24,124
on the Java script,
we will listen for the collision.
54
54
00:02:24,124 --> 00:02:26,276
So I'm gonna see when
collision takes place, and
55
55
00:02:26,276 --> 00:02:29,160
then we're gonna be executing
the specific behavior of jump etc.
56
56
00:02:29,160 --> 00:02:32,930
And also saying now it's time to attack.
57
57
00:02:32,930 --> 00:02:35,380
And then on our health script, well,
we're tracking current health and
58
58
00:02:35,380 --> 00:02:37,020
decrease in health.
59
59
00:02:37,020 --> 00:02:40,070
Okay, so, let's start the process
of giving our lizard what it needs.
60
60
00:02:40,070 --> 00:02:43,380
First of all, it needs an attack
animation, so let us go and
61
61
00:02:43,380 --> 00:02:44,500
get ourselves sorted out there.
62
62
00:02:44,500 --> 00:02:49,970
If you look for sprites, for me, it's the
Not In Use and we've got Lizard Attacking.
63
63
00:02:49,970 --> 00:02:52,060
I'm gonna drag that into Lizard.
64
64
00:02:52,060 --> 00:02:56,916
Now there might be something specific
about the lizard attacking Sprite sheet.
65
65
00:02:56,916 --> 00:02:59,590
when you have a look at it,
yep this is happening here.
66
66
00:02:59,590 --> 00:03:05,980
You can see 2048x607, and when we do our
calculations, there is I believe 15x6,
67
67
00:03:05,980 --> 00:03:09,220
it ends up with a weird something,
something point, something or rather.
68
68
00:03:09,220 --> 00:03:10,540
It doesn't quite make sense.
69
69
00:03:10,540 --> 00:03:14,280
What's happening here, is our original,
Sprite is bigger than that.
70
70
00:03:14,280 --> 00:03:17,303
Let me see if I right-click,
Show In Explorer,
71
71
00:03:17,303 --> 00:03:20,124
we'll see what the original
file is in here.
72
72
00:03:20,124 --> 00:03:24,994
I'm gonna right-click,
Show Properties, Properties,
73
73
00:03:24,994 --> 00:03:29,583
and we can see it is under Details,
3765x1116.
74
74
00:03:29,583 --> 00:03:34,328
So it's a much bigger image, but when
we look in Unity, it thinks it is 2048.
75
75
00:03:34,328 --> 00:03:37,937
And the reason that's happening
is our maximum size for
76
76
00:03:37,937 --> 00:03:40,640
our default has been capped at 2048.
77
77
00:03:40,640 --> 00:03:44,032
So if you click on default, you might
be clicked on one of the other buttons,
78
78
00:03:44,032 --> 00:03:46,320
this one that looks like the override for
PC, etc.
79
79
00:03:46,320 --> 00:03:51,025
If you click on Default and
change the maximum size to 4096,
80
80
00:03:51,025 --> 00:03:55,645
That means that it will allow that
size of image in our game, and
81
81
00:03:55,645 --> 00:04:01,069
it won't try to compress it when we
import our asset into our Unity build.
82
82
00:04:01,069 --> 00:04:02,720
So if I click, whoops,
[LAUGH] I clicked Revert.
83
83
00:04:02,720 --> 00:04:06,515
If I click the right size and
Apply, by default,
84
84
00:04:06,515 --> 00:04:11,060
then when we have a look at it,
it's 3765x1116.
85
85
00:04:11,060 --> 00:04:14,720
Now we can go ahead and
click on our Sprite editor,
86
86
00:04:14,720 --> 00:04:17,350
and you see all this stuff in here.
87
87
00:04:17,350 --> 00:04:21,580
I know, from doing my calculation already,
that when I do my cell size, it's going to
88
88
00:04:21,580 --> 00:04:28,400
be similar to previously, with the Lizard,
251x186, and then slice that up.
89
89
00:04:28,400 --> 00:04:31,762
Check on that,
looks like we've got it correct, good.
90
90
00:04:31,762 --> 00:04:33,473
And then click Apply.
91
91
00:04:33,473 --> 00:04:35,990
All right,
now we've sliced up our Sprite sheet.
92
92
00:04:35,990 --> 00:04:40,070
You might say, well, do we wanna not
have such big Sprite sheets in our game?
93
93
00:04:40,070 --> 00:04:42,150
Yes, if you're making
a mobile game in particular,
94
94
00:04:42,150 --> 00:04:43,760
you might wanna try to limit the size.
95
95
00:04:43,760 --> 00:04:49,130
We don't really need what's that,
15x6 animations of the guy eating.
96
96
00:04:49,130 --> 00:04:52,060
It's way too many animations,
but we're kind of constrained by
97
97
00:04:52,060 --> 00:04:56,170
the assets that we've got from this
asset pack, so we'll deal with it.
98
98
00:04:56,170 --> 00:04:59,810
But what's going on here is
Unity when you build your game,
99
99
00:04:59,810 --> 00:05:05,860
when you export it as a PC build, or
as a web build, or as a Android build.
100
100
00:05:05,860 --> 00:05:11,330
Then it will apply compression so that
raw file that I was looking at before,
101
101
00:05:11,330 --> 00:05:17,400
where is it, this raw file here won't end
up being, I think this was 16 megabytes.
102
102
00:05:17,400 --> 00:05:19,240
Pull this up, yeah, 16 megabytes.
103
103
00:05:19,240 --> 00:05:22,320
It'll be smaller in
whatever the game package
104
104
00:05:22,320 --> 00:05:25,710
is that's exported because Unity
is doing its own compression.
105
105
00:05:25,710 --> 00:05:27,470
Okay, now what do we need to do.
106
106
00:05:27,470 --> 00:05:29,590
Well we need to have a new animation.
107
107
00:05:29,590 --> 00:05:31,290
So let's click on our Lizard.
108
108
00:05:31,290 --> 00:05:33,160
Go to Animation.
109
109
00:05:33,160 --> 00:05:36,520
And where it says Lizard Jump,
Create New Click.
110
110
00:05:36,520 --> 00:05:42,040
Save this in Assets Animations, Attackers.
111
111
00:05:42,040 --> 00:05:47,800
This will be Lizard Attack
when the lizards attack, okay.
112
112
00:05:47,800 --> 00:05:49,290
Now, what do we wanna have in here?
113
113
00:05:49,290 --> 00:05:51,680
Well we need to click on our lizard?
114
114
00:05:51,680 --> 00:05:53,096
Yes, Add Property.
115
115
00:05:53,096 --> 00:05:54,172
Find the Body.
116
116
00:05:54,172 --> 00:05:55,470
Done this a few times now.
117
117
00:05:55,470 --> 00:05:58,290
Sprite Renderer,
all the way down to Sprite, click on plus.
118
118
00:05:58,290 --> 00:05:59,625
That'll bring in a couple of Sprites.
119
119
00:05:59,625 --> 00:06:01,496
I'm gonna go to my
Lizard Attacking Sprites.
120
120
00:06:01,496 --> 00:06:05,120
So they're being cut up, all 88 of them,
which is a little bit excessive.
121
121
00:06:05,120 --> 00:06:07,670
Generally I recommend not
bothering with 88, but
122
122
00:06:07,670 --> 00:06:09,500
we'll deal with what we've been given.
123
123
00:06:09,500 --> 00:06:11,500
Drag those over in.
124
124
00:06:11,500 --> 00:06:12,976
Okay, that all should be pretty good.
125
125
00:06:12,976 --> 00:06:13,890
Click on Play.
126
126
00:06:13,890 --> 00:06:15,142
Munch, munch, munch, munch.
127
127
00:06:15,142 --> 00:06:15,900
Munch, munch, munch, munch.
128
128
00:06:15,900 --> 00:06:20,410
All right, it looks cool, looks cool
indeed, and change it to 24 frames so
129
129
00:06:20,410 --> 00:06:21,280
we got the right speed.
130
130
00:06:23,220 --> 00:06:24,530
Yeah, nom, nom, nom, nom.
131
131
00:06:24,530 --> 00:06:25,520
Okay, nom noms!
132
132
00:06:25,520 --> 00:06:27,040
Good, we got our nom nom attack.
133
133
00:06:27,040 --> 00:06:28,400
Is that an attack?
134
134
00:06:28,400 --> 00:06:31,140
The attack of the nom noms, I'm sure
someone out there has heard of a game that
135
135
00:06:31,140 --> 00:06:33,860
has a nom nom attacking it somewhere.
136
136
00:06:33,860 --> 00:06:36,610
Okay, I hit Save cuz I haven't saved for
a while.
137
137
00:06:36,610 --> 00:06:38,550
Go to Animation, I run down to Animator,
138
138
00:06:38,550 --> 00:06:40,920
you can see Lizard Attack
has been dropped in there.
139
139
00:06:40,920 --> 00:06:42,520
Let me give ourselves
a little bit of space.
140
140
00:06:42,520 --> 00:06:45,740
Now, we need to be transitioning from
Walk to Attack, and Attack to Walk.
141
141
00:06:45,740 --> 00:06:50,020
We don't need to be transitioning from
Jump to Attack, because we're not going to
142
142
00:06:50,020 --> 00:06:54,560
allow the lizard to be attacking anything
until it's totally entered the scene and
143
143
00:06:54,560 --> 00:06:55,310
finished its jump.
144
144
00:06:55,310 --> 00:06:58,990
So click on Lizard Walk, right-click
Make Transition to Lizard Attack.
145
145
00:06:58,990 --> 00:07:01,740
Lizard Attack, right-click
Make Transition to Lizard Walk.
146
146
00:07:01,740 --> 00:07:05,530
We'll click on over in parameters,
we need to add a new parameter
147
147
00:07:05,530 --> 00:07:10,220
which will be a ball, and
the ball will be called is attacking.
148
148
00:07:11,780 --> 00:07:13,430
Great stuff, click click.
149
149
00:07:14,540 --> 00:07:17,112
Lets just test that out with
the guy we've got now seen,
150
150
00:07:17,112 --> 00:07:18,821
once he's finished doing his jump.
151
151
00:07:20,518 --> 00:07:24,610
Jump, now if I click on Attacking,
he's attacking, yep.
152
152
00:07:24,610 --> 00:07:25,320
Starting and stopping.
153
153
00:07:25,320 --> 00:07:25,840
Okay, cool.
And
154
154
00:07:25,840 --> 00:07:28,150
the problem is he's still
moving across the screen.
155
155
00:07:28,150 --> 00:07:29,570
What do we need to do there?
156
156
00:07:29,570 --> 00:07:31,092
Little mini challenge for you.
157
157
00:07:31,092 --> 00:07:33,829
How do we stop him sliding
across the screen?
158
158
00:07:33,829 --> 00:07:38,280
Okay, the way we do that is
we find the attack animation.
159
159
00:07:38,280 --> 00:07:41,080
We put in a event right
at the very very start.
160
160
00:07:41,080 --> 00:07:43,652
Click on our Event button there,
Add Event.
161
161
00:07:43,652 --> 00:07:48,105
And in our Function, we select
SetMovementSpeed, and set that to 0.
162
162
00:07:48,105 --> 00:07:52,800
Now, when we click on our Animator,
click on Play.
163
163
00:07:52,800 --> 00:07:56,140
We've got our little checkbox we
can click isAttacking on and off.
164
164
00:07:56,140 --> 00:08:00,712
Attacking, he stops,
turn off isAttacking, [SOUND] okay, and
165
165
00:08:00,712 --> 00:08:04,195
what's happening here is another test for
you.
166
166
00:08:04,195 --> 00:08:06,680
Why is he staying in his lizard attack.
167
167
00:08:06,680 --> 00:08:10,250
It's because we're not setting,
168
168
00:08:10,250 --> 00:08:13,540
where are we in here in our
lizard attack transition.
169
169
00:08:13,540 --> 00:08:17,230
We have Exit Time ticked on,
so we tick Exit Time off.
170
170
00:08:17,230 --> 00:08:21,160
On here I'm going to transition to 0,
just cuz I like to do that.
171
171
00:08:21,160 --> 00:08:24,161
And then transition is 0,
and has Exit Time off.
172
172
00:08:24,161 --> 00:08:26,076
So the moment the transition happens,
173
173
00:08:26,076 --> 00:08:28,404
we want it to go into
the other animation state.
174
174
00:08:28,404 --> 00:08:31,357
It's good to do these things when you
can still just tick your box on and off,
175
175
00:08:31,357 --> 00:08:34,589
cuz if you have to wait until you've got
your code written, sometimes it's a bit of
176
176
00:08:34,589 --> 00:08:38,080
a pain to figure out is that my code or
is that the way I've set up my animator?
177
177
00:08:38,080 --> 00:08:41,770
Okay, so he's not stopping at all,
178
178
00:08:41,770 --> 00:08:47,710
that is because I've broken something,
my transition here, okay, so,
179
179
00:08:47,710 --> 00:08:51,060
my tick box some of you have been probably
yelling at me Rick, you're an idiot.
180
180
00:08:51,060 --> 00:08:51,840
I am an idiot.
181
181
00:08:51,840 --> 00:08:52,770
I've been ticking the box,
182
182
00:08:52,770 --> 00:08:56,410
it hasn't actually been doing anything
because I hadn't put my conditions in yet.
183
183
00:08:56,410 --> 00:08:58,850
It was just going from Walk,
to Attack, and then back to Walk.
184
184
00:08:58,850 --> 00:09:01,267
And I thought, I made one of those,
I'm pushing the button, and
185
185
00:09:01,267 --> 00:09:02,800
[LAUGH] it's working, it wasn't.
186
186
00:09:02,800 --> 00:09:06,150
Okay, so let's add our conditions on
the transition from Walk to Attack.
187
187
00:09:06,150 --> 00:09:09,090
It'd be isAttacking is true,
that's correct.
188
188
00:09:09,090 --> 00:09:12,990
Now, on the other way around,
it's gonna be isAttacking is false.
189
189
00:09:12,990 --> 00:09:14,717
So I was clicking
the little + button there,
190
190
00:09:14,717 --> 00:09:17,862
isAttacking populated automatically, and
then changing it from true to false.
191
191
00:09:17,862 --> 00:09:22,730
Now, unless I've done some other
dumb thing, which is quite possible.
192
192
00:09:22,730 --> 00:09:25,140
Let me click the box,
bump, stops, and eats.
193
193
00:09:26,520 --> 00:09:28,910
There we go, golden, okay.
194
194
00:09:28,910 --> 00:09:31,740
So we've got the behavior that we want,
nom, nom, nom, nom.
195
195
00:09:31,740 --> 00:09:34,180
And now we're ready for him to do what?
196
196
00:09:34,180 --> 00:09:38,420
We're ready for him to have that code,
so let's click on Lizard.
197
197
00:09:38,420 --> 00:09:41,130
Just make sure everything's
applied back in the prefab.
198
198
00:09:41,130 --> 00:09:43,280
We'll go open a script,
which script should we open up?
199
199
00:09:43,280 --> 00:09:45,253
We'll open up the Attacker script.
200
200
00:09:46,604 --> 00:09:50,060
We'll start by creating a variable
which will be the current target, so
201
201
00:09:50,060 --> 00:09:52,280
I'll make it a game object for now.
202
202
00:09:52,280 --> 00:09:54,000
We might make it a defender in the future,
but
203
203
00:09:54,000 --> 00:09:57,180
we'll make a GameObject
called this currentTarget.
204
204
00:09:57,180 --> 00:09:58,320
So this is who you're targeting,
205
205
00:09:58,320 --> 00:10:01,100
only one at a time in our
particular game at the moment.
206
206
00:10:01,100 --> 00:10:04,010
And now we can scroll all the way down
to the bottom of our script underneath
207
207
00:10:04,010 --> 00:10:05,220
SetMovementSpeed.
208
208
00:10:05,220 --> 00:10:10,810
We'll make ourselves a public method,
public void, and we'll call this Attack.
209
209
00:10:10,810 --> 00:10:13,500
And in Attack we need to
know who we are attacking.
210
210
00:10:13,500 --> 00:10:16,590
So we're going to ask for
a GameObject and we'll call it target.
211
211
00:10:17,640 --> 00:10:18,980
And the moment we are attacking,
212
212
00:10:18,980 --> 00:10:22,440
what we want to do is set
our animator to attacking.
213
213
00:10:22,440 --> 00:10:24,120
So here's another mini challenge for you.
214
214
00:10:24,120 --> 00:10:30,350
Go ahead and write the line that will
set our animation to being attacking.
215
215
00:10:30,350 --> 00:10:32,220
Might need to go have a look
at some of our other code, but
216
216
00:10:32,220 --> 00:10:33,630
there's a little mini challenge for you.
217
217
00:10:34,660 --> 00:10:36,530
Okay, first of all we
need to get the animator.
218
218
00:10:36,530 --> 00:10:41,325
So GetComponent, Animator,
and what we'll do,
219
219
00:10:41,325 --> 00:10:47,580
what we'll SetBool and
we'll SetBool to be what, isAttacking.
220
220
00:10:47,580 --> 00:10:51,302
Now I made a big mess up last time
on this, let's go to isAttacking.
221
221
00:10:51,302 --> 00:10:56,217
And highlight it, copy,
back over into here, paste.
222
222
00:10:56,217 --> 00:10:58,500
That actually did get it correct,
but you never know.
223
223
00:10:58,500 --> 00:11:00,170
And we'll say that will now be true.
224
224
00:11:01,300 --> 00:11:06,470
And then we also need to set whatever
we've just parsed in when this called,
225
225
00:11:06,470 --> 00:11:08,690
when attack is called,
we parsed in the target.
226
226
00:11:08,690 --> 00:11:16,090
So now we'll say that our
currentTarget = what, equals target.
227
227
00:11:16,090 --> 00:11:16,590
There we go.
228
228
00:11:17,820 --> 00:11:21,650
Now, we need to have the moment
where we call out attack.
229
229
00:11:21,650 --> 00:11:23,720
And to do that we'll create
ourselves a new script.
230
230
00:11:23,720 --> 00:11:27,330
And I said before we'll have a script for
every particular attacker.
231
231
00:11:27,330 --> 00:11:29,007
Say now, scripts folder, right click.
232
232
00:11:32,946 --> 00:11:35,690
Create C# Script, I'll call this Lizard.
233
233
00:11:37,540 --> 00:11:39,020
Let's open up Lizard.
234
234
00:11:39,020 --> 00:11:41,800
Gonna get rid of Start and Update,
I don't think I'm gonna need those.
235
235
00:11:41,800 --> 00:11:47,590
What we do need is an OnTrigger into 2D,
so void OnTrigger, enter 2D.
236
236
00:11:48,660 --> 00:11:50,990
And just to be really clear
instead of calling it collision,
237
237
00:11:50,990 --> 00:11:53,420
I'm gonna call it otherCollider.
238
238
00:11:55,000 --> 00:11:55,810
otherCollider, or
239
239
00:11:55,810 --> 00:11:59,710
the thing we collided with's collider
is basically what this is in here.
240
240
00:11:59,710 --> 00:12:04,780
And then we'll create ourselves
a GameObject that we'll call otherObject,
241
241
00:12:04,780 --> 00:12:06,620
the other thing that we've
bumped into just now.
242
242
00:12:06,620 --> 00:12:13,040
And that will equal
the otherCollider.gameObject.
243
243
00:12:13,040 --> 00:12:15,677
Okay, just establishing that
we have this game object.
244
244
00:12:15,677 --> 00:12:20,010
So we're taking it from just being,
I know about the collider of an object,
245
245
00:12:20,010 --> 00:12:23,349
to be being I now about the game
object I've just bumped into.
246
246
00:12:23,349 --> 00:12:27,260
Now, I want to write an if statement.
247
247
00:12:27,260 --> 00:12:30,950
Where I'm looking to see if it's
a defender, and if it is an attack.
248
248
00:12:30,950 --> 00:12:33,320
And this is where I've got a challenge for
you.
249
249
00:12:33,320 --> 00:12:35,180
That challenge is finish
our collision event.
250
250
00:12:35,180 --> 00:12:38,910
So, I've written this in my,
this is a pretty bright green, isn't it?
251
251
00:12:38,910 --> 00:12:41,180
Okay, in my little pseudo
comment code here.
252
252
00:12:41,180 --> 00:12:44,400
If the other object has
a defender component,
253
253
00:12:44,400 --> 00:12:47,850
then call our public attack
method we just created.
254
254
00:12:47,850 --> 00:12:50,740
So there's a little if statement I'd
like for you to take on and write.
255
255
00:12:50,740 --> 00:12:52,961
So give it your best shot and
I'll see you back here when you're done.
256
256
00:12:54,912 --> 00:13:02,210
Okay, so if otherObject, that we've
just created, otherObject.GetComponent.
257
257
00:13:02,210 --> 00:13:04,645
And what sort of component
does it need to have?
258
258
00:13:04,645 --> 00:13:06,320
It needs to have a Defender component.
259
259
00:13:06,320 --> 00:13:08,040
We wanna know, are you a defender?
260
260
00:13:08,040 --> 00:13:11,570
If not, we are not interested, but
if you do have a defender component,
261
261
00:13:11,570 --> 00:13:16,410
that means you're worthy of being
attacked, then we wanna get my object, so
262
262
00:13:16,410 --> 00:13:19,310
my lizard object's attacker script.
263
263
00:13:19,310 --> 00:13:22,885
So GetComponent, because that
belongs to me as a game object, so
264
264
00:13:22,885 --> 00:13:24,970
I have a component which is Attacker.
265
265
00:13:26,230 --> 00:13:30,570
And then on that we call the attack
script, sorry the attack method.
266
266
00:13:30,570 --> 00:13:33,918
And the attack will attack what,
otherObject.
267
267
00:13:33,918 --> 00:13:37,390
It's a little bit tricky but
basically we are bumping into something,
268
268
00:13:37,390 --> 00:13:41,410
we're saying it's a game object, does it
have a defender script and then now we
269
269
00:13:41,410 --> 00:13:45,550
know from this point on that this is the
thing we're attacking, this otherObject.
270
270
00:13:45,550 --> 00:13:46,530
So let's see how this work.
271
271
00:13:46,530 --> 00:13:47,830
Save that up.
272
272
00:13:47,830 --> 00:13:49,370
Jump back over into Unity.
273
273
00:13:49,370 --> 00:13:50,185
Now click on Lizard.
274
274
00:13:50,185 --> 00:13:54,539
Remember or remembering, I've just spent
the last five minutes wondering why my
275
275
00:13:54,539 --> 00:13:58,955
code hasn't work and I've just edited that
piece out, is I've forgotten to add my
276
276
00:13:58,955 --> 00:14:02,323
Lizard component to my Lizard,
which is what we should do now.
277
277
00:14:02,323 --> 00:14:04,633
So add lizard, apply that to the prefab so
278
278
00:14:04,633 --> 00:14:07,350
it actually knows the code
that we've created.
279
279
00:14:07,350 --> 00:14:08,212
It knows about it.
280
280
00:14:08,212 --> 00:14:11,960
And then, well I'm here I'm gonna
click on isTrigger as well, and
281
281
00:14:11,960 --> 00:14:14,642
the box Collider for
the lizard, click on Apply.
282
282
00:14:14,642 --> 00:14:19,600
Click Play, and then I think it's gonna be
the tombstone that's gonna work the best
283
283
00:14:19,600 --> 00:14:22,080
for this,
cuz currently we've tuned our cactus,
284
284
00:14:22,080 --> 00:14:26,040
and our gnome to completely
smash things as they come along.
285
285
00:14:26,040 --> 00:14:29,320
So he stops and starts nibbling on it,
that's great, nom, nom, nom, nom.
286
286
00:14:29,320 --> 00:14:32,850
And we'll see if we can get it as well
with a cactus, and there we go yeah.
287
287
00:14:32,850 --> 00:14:35,690
So they're now stopping, they're
attacking, we don't have the proper
288
288
00:14:35,690 --> 00:14:38,930
health component setup just yet so they're
gonna stand there forever attacking.
289
289
00:14:38,930 --> 00:14:42,060
But they're now switching into
their transition state based upon
290
290
00:14:42,060 --> 00:14:43,140
our animation trigger.
291
291
00:14:43,140 --> 00:14:46,690
So great work, you can probably
tune your colliders a little bit so
292
292
00:14:46,690 --> 00:14:50,080
it's a little bit tighter, so it looks
like they're actually nibbling on things.
293
293
00:14:50,080 --> 00:14:51,630
So great stuff and
I'll see you in the next video.
29326
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.