Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1 1
[SOUND] >> Hello again, 2
2
in this video we are evolving our attackers so that when they bump into 3
3
a defender and, here we go, something, don't shoot, there we go. 4
4
They start to switch animation state to attacking and 5
5
start to attack the defenders. 6
6
So let's jump in and get started. 7
7
Right, let's have a look at what we have got. 8
8
In our attackers, we have got one attacker which is the lizard and looking at it now, 9
9
the collision is in slightly the wrong spot. 10
10
So I'm gonna change the collision, clicking on Edit Collider, just move it up 11
11
so it's actually over the lizard and not just hanging out in a weird spot. 12
12
There we go, apply that back to be PreFab. 13
13
All right, now I've got one lizard. 14
14
What else do we need? 15
15
Who else do we need in our game? 16
16
Well, let's have a look at that. 17
17
I am gonna have in my execution of this game a lizard, a fox, a weird jelly or 18
18
jello kind of dude, and this guy who's called Jabba for some reason, 19
19
I guess because he looks like Jabba the Hutt. 20
20
And well done, Rick. 21
21
Good work. 22
22
[LAUGH] I'm just like Sherlock Holmes for figuring that out, aren't I? 23
23
Okay, so I've got speed, attack, health, and a special ability. 24
24
This speed and attack and health, I'm not gonna go into too much detail. 25
25
It's kind of regular guy, fast guy. 26
26
And then this guy's a little bit different, and 27
27
that guy's a little bit different as well. 28
28
In terms of the special, the lizard doesn't have a special, 29
29
he just runs up and hits things. 30
30
The fox is gonna jump over particular things, 31
31
specifically the gravestone or the, is that what we're calling it? 32
32
Gravestone, yes. 33
33
That we put into our game doesn't stop the fox. 34
34
The Jello guy, gotta make myself North Americanized, is Ghosting. 35
35
So he doesn't bump into anything. 36
36
Just goes walk, walk, walk, walk, walk, right through everything. 37
37
And then this big old guy goes really slowly. 38
38
Classic kind of tank dude smashes into stuff. 39
39
And I'll leave a question mark here. 40
40
This is gonna be something that at some point you can go ahead and 41
41
make a cool special move for the Java character. 42
42
Now what do we need to do in what spot? 43
43
We've gone our three scripts I'm gonna be referring to. 44
44
Attacker and then Lizard script or 45
45
Fox scripts is gonna be specific to the individual attackers. 46
46
So each character, each attacker will have its own script and then health. 47
47
With an attacker, we want it to move left, we've done that, set speed, 48
48
done that, update animation state, we'll do that, and attack a specific target, 49
49
we'll do that as well. 50
50
What I mean by specific is we want our attackers to only be attacking 51
51
one defender at once. 52
52
And then on, say, the lizard script, or on the Fox script, or 53
53
on the Java script, we will listen for the collision. 54
54
So I'm gonna see when collision takes place, and 55
55
then we're gonna be executing the specific behavior of jump etc. 56
56
And also saying now it's time to attack. 57
57
And then on our health script, well, we're tracking current health and 58
58
decrease in health. 59
59
Okay, so, let's start the process of giving our lizard what it needs. 60
60
First of all, it needs an attack animation, so let us go and 61
61
get ourselves sorted out there. 62
62
If you look for sprites, for me, it's the Not In Use and we've got Lizard Attacking. 63
63
I'm gonna drag that into Lizard. 64
64
Now there might be something specific about the lizard attacking Sprite sheet. 65
65
when you have a look at it, yep this is happening here. 66
66
You can see 2048x607, and when we do our calculations, there is I believe 15x6, 67
67
it ends up with a weird something, something point, something or rather. 68
68
It doesn't quite make sense. 69
69
What's happening here, is our original, Sprite is bigger than that. 70
70
Let me see if I right-click, Show In Explorer, 71
71
we'll see what the original file is in here. 72
72
I'm gonna right-click, Show Properties, Properties, 73
73
and we can see it is under Details, 3765x1116. 74
74
So it's a much bigger image, but when we look in Unity, it thinks it is 2048. 75
75
And the reason that's happening is our maximum size for 76
76
our default has been capped at 2048. 77
77
So if you click on default, you might be clicked on one of the other buttons, 78
78
this one that looks like the override for PC, etc. 79
79
If you click on Default and change the maximum size to 4096, 80
80
That means that it will allow that size of image in our game, and 81
81
it won't try to compress it when we import our asset into our Unity build. 82
82
So if I click, whoops, [LAUGH] I clicked Revert. 83
83
If I click the right size and Apply, by default, 84
84
then when we have a look at it, it's 3765x1116. 85
85
Now we can go ahead and click on our Sprite editor, 86
86
and you see all this stuff in here. 87
87
I know, from doing my calculation already, that when I do my cell size, it's going to 88
88
be similar to previously, with the Lizard, 251x186, and then slice that up. 89
89
Check on that, looks like we've got it correct, good. 90
90
And then click Apply. 91
91
All right, now we've sliced up our Sprite sheet. 92
92
You might say, well, do we wanna not have such big Sprite sheets in our game? 93
93
Yes, if you're making a mobile game in particular, 94
94
you might wanna try to limit the size. 95
95
We don't really need what's that, 15x6 animations of the guy eating. 96
96
It's way too many animations, but we're kind of constrained by 97
97
the assets that we've got from this asset pack, so we'll deal with it. 98
98
But what's going on here is Unity when you build your game, 99
99
when you export it as a PC build, or as a web build, or as a Android build. 100
100
Then it will apply compression so that raw file that I was looking at before, 101
101
where is it, this raw file here won't end up being, I think this was 16 megabytes. 102
102
Pull this up, yeah, 16 megabytes. 103
103
It'll be smaller in whatever the game package 104
104
is that's exported because Unity is doing its own compression. 105
105
Okay, now what do we need to do. 106
106
Well we need to have a new animation. 107
107
So let's click on our Lizard. 108
108
Go to Animation. 109
109
And where it says Lizard Jump, Create New Click. 110
110
Save this in Assets Animations, Attackers. 111
111
This will be Lizard Attack when the lizards attack, okay. 112
112
Now, what do we wanna have in here? 113
113
Well we need to click on our lizard? 114
114
Yes, Add Property. 115
115
Find the Body. 116
116
Done this a few times now. 117
117
Sprite Renderer, all the way down to Sprite, click on plus. 118
118
That'll bring in a couple of Sprites. 119
119
I'm gonna go to my Lizard Attacking Sprites. 120
120
So they're being cut up, all 88 of them, which is a little bit excessive. 121
121
Generally I recommend not bothering with 88, but 122
122
we'll deal with what we've been given. 123
123
Drag those over in. 124
124
Okay, that all should be pretty good. 125
125
Click on Play. 126
126
Munch, munch, munch, munch. 127
127
Munch, munch, munch, munch. 128
128
All right, it looks cool, looks cool indeed, and change it to 24 frames so 129
129
we got the right speed. 130
130
Yeah, nom, nom, nom, nom. 131
131
Okay, nom noms! 132
132
Good, we got our nom nom attack. 133
133
Is that an attack? 134
134
The attack of the nom noms, I'm sure someone out there has heard of a game that 135
135
has a nom nom attacking it somewhere. 136
136
Okay, I hit Save cuz I haven't saved for a while. 137
137
Go to Animation, I run down to Animator, 138
138
you can see Lizard Attack has been dropped in there. 139
139
Let me give ourselves a little bit of space. 140
140
Now, we need to be transitioning from Walk to Attack, and Attack to Walk. 141
141
We don't need to be transitioning from Jump to Attack, because we're not going to 142
142
allow the lizard to be attacking anything until it's totally entered the scene and 143
143
finished its jump. 144
144
So click on Lizard Walk, right-click Make Transition to Lizard Attack. 145
145
Lizard Attack, right-click Make Transition to Lizard Walk. 146
146
We'll click on over in parameters, we need to add a new parameter 147
147
which will be a ball, and the ball will be called is attacking. 148
148
Great stuff, click click. 149
149
Lets just test that out with the guy we've got now seen, 150
150
once he's finished doing his jump. 151
151
Jump, now if I click on Attacking, he's attacking, yep. 152
152
Starting and stopping. 153
153
Okay, cool. And 154
154
the problem is he's still moving across the screen. 155
155
What do we need to do there? 156
156
Little mini challenge for you. 157
157
How do we stop him sliding across the screen? 158
158
Okay, the way we do that is we find the attack animation. 159
159
We put in a event right at the very very start. 160
160
Click on our Event button there, Add Event. 161
161
And in our Function, we select SetMovementSpeed, and set that to 0. 162
162
Now, when we click on our Animator, click on Play. 163
163
We've got our little checkbox we can click isAttacking on and off. 164
164
Attacking, he stops, turn off isAttacking, [SOUND] okay, and 165
165
what's happening here is another test for you. 166
166
Why is he staying in his lizard attack. 167
167
It's because we're not setting, 168
168
where are we in here in our lizard attack transition. 169
169
We have Exit Time ticked on, so we tick Exit Time off. 170
170
On here I'm going to transition to 0, just cuz I like to do that. 171
171
And then transition is 0, and has Exit Time off. 172
172
So the moment the transition happens, 173
173
we want it to go into the other animation state. 174
174
It's good to do these things when you can still just tick your box on and off, 175
175
cuz if you have to wait until you've got your code written, sometimes it's a bit of 176
176
a pain to figure out is that my code or is that the way I've set up my animator? 177
177
Okay, so he's not stopping at all, 178
178
that is because I've broken something, my transition here, okay, so, 179
179
my tick box some of you have been probably yelling at me Rick, you're an idiot. 180
180
I am an idiot. 181
181
I've been ticking the box, 182
182
it hasn't actually been doing anything because I hadn't put my conditions in yet. 183
183
It was just going from Walk, to Attack, and then back to Walk. 184
184
And I thought, I made one of those, I'm pushing the button, and 185
185
[LAUGH] it's working, it wasn't. 186
186
Okay, so let's add our conditions on the transition from Walk to Attack. 187
187
It'd be isAttacking is true, that's correct. 188
188
Now, on the other way around, it's gonna be isAttacking is false. 189
189
So I was clicking the little + button there, 190
190
isAttacking populated automatically, and then changing it from true to false. 191
191
Now, unless I've done some other dumb thing, which is quite possible. 192
192
Let me click the box, bump, stops, and eats. 193
193
There we go, golden, okay. 194
194
So we've got the behavior that we want, nom, nom, nom, nom. 195
195
And now we're ready for him to do what? 196
196
We're ready for him to have that code, so let's click on Lizard. 197
197
Just make sure everything's applied back in the prefab. 198
198
We'll go open a script, which script should we open up? 199
199
We'll open up the Attacker script. 200
200
We'll start by creating a variable which will be the current target, so 201
201
I'll make it a game object for now. 202
202
We might make it a defender in the future, but 203
203
we'll make a GameObject called this currentTarget. 204
204
So this is who you're targeting, 205
205
only one at a time in our particular game at the moment. 206
206
And now we can scroll all the way down to the bottom of our script underneath 207
207
SetMovementSpeed. 208
208
We'll make ourselves a public method, public void, and we'll call this Attack. 209
209
And in Attack we need to know who we are attacking. 210
210
So we're going to ask for a GameObject and we'll call it target. 211
211
And the moment we are attacking, 212
212
what we want to do is set our animator to attacking. 213
213
So here's another mini challenge for you. 214
214
Go ahead and write the line that will set our animation to being attacking. 215
215
Might need to go have a look at some of our other code, but 216
216
there's a little mini challenge for you. 217
217
Okay, first of all we need to get the animator. 218
218
So GetComponent, Animator, and what we'll do, 219
219
what we'll SetBool and we'll SetBool to be what, isAttacking. 220
220
Now I made a big mess up last time on this, let's go to isAttacking. 221
221
And highlight it, copy, back over into here, paste. 222
222
That actually did get it correct, but you never know. 223
223
And we'll say that will now be true. 224
224
And then we also need to set whatever we've just parsed in when this called, 225
225
when attack is called, we parsed in the target. 226
226
So now we'll say that our currentTarget = what, equals target. 227
227
There we go. 228
228
Now, we need to have the moment where we call out attack. 229
229
And to do that we'll create ourselves a new script. 230
230
And I said before we'll have a script for every particular attacker. 231
231
Say now, scripts folder, right click. 232
232
Create C# Script, I'll call this Lizard. 233
233
Let's open up Lizard. 234
234
Gonna get rid of Start and Update, I don't think I'm gonna need those. 235
235
What we do need is an OnTrigger into 2D, so void OnTrigger, enter 2D. 236
236
And just to be really clear instead of calling it collision, 237
237
I'm gonna call it otherCollider. 238
238
otherCollider, or 239
239
the thing we collided with's collider is basically what this is in here. 240
240
And then we'll create ourselves a GameObject that we'll call otherObject, 241
241
the other thing that we've bumped into just now. 242
242
And that will equal the otherCollider.gameObject. 243
243
Okay, just establishing that we have this game object. 244
244
So we're taking it from just being, I know about the collider of an object, 245
245
to be being I now about the game object I've just bumped into. 246
246
Now, I want to write an if statement. 247
247
Where I'm looking to see if it's a defender, and if it is an attack. 248
248
And this is where I've got a challenge for you. 249
249
That challenge is finish our collision event. 250
250
So, I've written this in my, this is a pretty bright green, isn't it? 251
251
Okay, in my little pseudo comment code here. 252
252
If the other object has a defender component, 253
253
then call our public attack method we just created. 254
254
So there's a little if statement I'd like for you to take on and write. 255
255
So give it your best shot and I'll see you back here when you're done. 256
256
Okay, so if otherObject, that we've just created, otherObject.GetComponent. 257
257
And what sort of component does it need to have? 258
258
It needs to have a Defender component. 259
259
We wanna know, are you a defender? 260
260
If not, we are not interested, but if you do have a defender component, 261
261
that means you're worthy of being attacked, then we wanna get my object, so 262
262
my lizard object's attacker script. 263
263
So GetComponent, because that belongs to me as a game object, so 264
264
I have a component which is Attacker. 265
265
And then on that we call the attack script, sorry the attack method. 266
266
And the attack will attack what, otherObject. 267
267
It's a little bit tricky but basically we are bumping into something, 268
268
we're saying it's a game object, does it have a defender script and then now we 269
269
know from this point on that this is the thing we're attacking, this otherObject. 270
270
So let's see how this work. 271
271
Save that up. 272
272
Jump back over into Unity. 273
273
Now click on Lizard. 274
274
Remember or remembering, I've just spent the last five minutes wondering why my 275
275
code hasn't work and I've just edited that piece out, is I've forgotten to add my 276
276
Lizard component to my Lizard, which is what we should do now. 277
277
So add lizard, apply that to the prefab so 278
278
it actually knows the code that we've created. 279
279
It knows about it. 280
280
And then, well I'm here I'm gonna click on isTrigger as well, and 281
281
the box Collider for the lizard, click on Apply. 282
282
Click Play, and then I think it's gonna be the tombstone that's gonna work the best 283
283
for this, cuz currently we've tuned our cactus, 284
284
and our gnome to completely smash things as they come along. 285
285
So he stops and starts nibbling on it, that's great, nom, nom, nom, nom. 286
286
And we'll see if we can get it as well with a cactus, and there we go yeah. 287
287
So they're now stopping, they're attacking, we don't have the proper 288
288
health component setup just yet so they're gonna stand there forever attacking. 289
289
But they're now switching into their transition state based upon 290
290
our animation trigger. 291
291
So great work, you can probably tune your colliders a little bit so 292
292
it's a little bit tighter, so it looks like they're actually nibbling on things. 293
293
So great stuff and I'll see you in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.