All language subtitles for 22. Implementing Health & Damage

af Afrikaans
ak Akan
sq Albanian
am Amharic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

1 1

In this video, we're implementing our damage systems so that blank, 2

2

there we go, we can shoot projectiles that kill enemies that have health. 3

3

And when they get to zero, they're destroyed. 4

4

So, let's jump in and get started. 5

5

Okay, let's start off by implementing some colliders. 6

6

I'm gonna find my Zucchini and add a component, 7

7

which will be a collider, box collider 2D. 8

8

I think that's pretty good. 9

9

It doesn't need to be perfect with the Zucchini. 10

10

I'll edit just a little bit, bring it in. 11

11

Bring it down, bring it in just so it's reasonably tight. 12

12

Click on the Edit Collider. 13

13

Okay, there we go. 14

14

Pretty good. It just kinda has to strike the center of 15

15

the Zucchini. 16

16

We're in lanes, so we don't need super precise collision. 17

17

That's great, apply that back to the prefab, excellent. 18

18

I think I can remove my Zucchini from the scene now. 19

19

We'll just be using prefabs when we instantiate them. 20

20

Now, let's find the lizard. 21

21

The lizard, I do need to drag a lizard into the scene, so 22

22

I can see what's going on. 23

23

Click on ADD COMPONENT, Box Collider 2D. 24

24

That's around the entire outside, which is a bit big. 25

25

I'm gonna switch onto Lizard Walk. 26

26

I think that's where I wanna have my collider around wherever he walks, because 27

27

during the jump, I think the wizard should be little and even vulnerable. 28

28

Jump, jump, jump, jump. 29

29

Okay, during that stage, I don't really want my cactus to be hitting it. 30

30

So I will just wrap my collider around, what it looks like when he's walking. 31

31

So edit collider on the box, collider move this in. 32

32

Move that in as well, move that down. 33

33

Now move that whoops. 34

34

That's bit of a pain when that happens. 35

35

Back on Edit Collider. 36

36

And there we go, excellent. 37

37

Apply that back to the prefab. 38

38

Very good, and once again, I don't think I need to my lizard any more. 39

39

What I will do is find a Zucchini and find where we, 40

40

is Trigger is on the Box Collider 2D. 41

41

Is Trigger, tick that on. 42

42

Now, one thing we need to review any time we're doing collisions, 43

43

is our collision matrix. 44

44

So let's have a quick look at that. 45

45

We can see all of these grids in here. 46

46

We've looked at these before. 47

47

We're using a Trigger Static Trigger Collidor, 48

48

Dynamic Rigidbody Trigger Collidor, Kinematic Rigidbody Trigger Collidor. 49

49

Well it's not static and it's not dynamic, 50

50

so it's gonna be a Kinematic Rigidbody Trigger Collidor which reminds me. 51

51

We don't have a rigidbody anywhere. 52

52

So I'll find my lizard. 53

53

And add a rigidbody. 54

54

I didn't list that out in my requirements. 55

55

This is one of those things when you do the requirements, 56

56

you think you're being pretty thorough. 57

57

But we missed, that we need a rigidbody. 58

58

I'll switch this to kinematic, cuz we're saying walk across the screen this way. 59

59

I'm putting a rigidbody onto the lizard. 60

60

And we could put a rigidbody on the projectile as well. 61

61

Actually, let's do that just so we are being thorough on the Zucchini. 62

62

Add Component, RigidBody 2D. 63

63

And it's gonna work without this, I believe, but we'll say it's Kinematic. 64

64

Now, temporary over into your scripts. 65

65

What script are we looking for 66

66

here as I move my microphone out of the way a little bit? 67

67

I'm looking for the Projectile script. 68

68

Open that up in Visual Studio. 69

69

Let's start a new line, where we're going to check for the trigger. 70

70

So we'll say void OnTriggerEnter2D, 71

71

and the auto completes a bunch of stuff for us. 72

72

I'm gonna rename from collision here, 73

73

this is what's getting passed in, rename to this to otherCollider. 74

74

otherCollision, we'll cal it otherCollider. 75

75

You can call it whatever you want. 76

76

You could call it bob if you wanted to, but 77

77

I wanted to just be very clear that we're talking about the other things collider. 78

78

So this is the projectile, and when we bump into anything else, 79

79

we wanna know details about the anything else, so that's the otherCollider. 80

80

No we haven't even done this for 81

81

a while still be printing, so Debug .Log, 82

82

and then ("I hit: " what do we hit + otherCollider-name). 83

83

So we'll just make sure that our collision is working. 84

84

Before we go anywhere else on collision, you always wanna make sure [LAUGH] it's 85

85

working, or else you scratch your head wondering what's going on. 86

86

So back over into here, click on Play. 87

87

Once it's finished compiling and thinking, click on Play, open up the Console. 88

88

A couple of warnings, we're not using that, that's fine. 89

89

And then when this hits here, boing, we should get, I hit a lizard, excellent. 90

90

Okay, so collision is successfully working. 91

91

That's really important for 92

92

us to be confident hat we're on top of that, good stuff. 93

93

Okay, so when we have that collision moment, basically in here, 94

94

what we wanna be doing is reduce health. 95

95

That's what we wanna be doing in here. 96

96

So how do we go about doing that? 97

97

Well, we would call some sort of say, DealDamage method. 98

98

And DealDamage(), we haven't created that yet, 99

99

it doesn't know where it's coming from. 100

100

So let's go and create all of that mechanism. 101

101

So jump back over into Unity, we'll need to make ourselves a new script, 102

102

which will be called Health. 103

103

Create C# script, Health. 104

104

I'll just double click on Health. 105

105

Okay, so let's start off by giving ourselves a notion of how much health 106

106

the particular thing will have. 107

107

So SerializeField, and then this will be a float, 108

108

we'll call this health, an issue like that 100f seems pretty good. 109

109

Let's have a quick look at our checklist, 110

110

we're going through the mechanism now the Health script. 111

111

We've created Health script, serialize health, yes, create DealDamage, 112

112

let's do that. 113

113

So for now, I'm going to just get rid of start and update, 114

114

we put them back in if we need them, create a public method, 115

115

cuz we need to be accessing this from the projectile. 116

116

The projectile's gonna say, I hit something, and we call the Deal Damage, so 117

117

we call DealDamage. 118

118

And what do we need at this point? 119

119

Well we need to know how much damage to deal, 120

120

and we want that to be dependent upon the particular projectile that's hit you. 121

121

So we'll say, when DealDamage is called, 122

122

we require you to let us know of type float how much damage it is, 123

123

that you need to be passing back in to DealDamage. 124

124

Okay, open our curly braces. 125

125

And then within here we'll have 126

126

the standard health -= damage;. 127

127

So we're saying, whatever health you have at the moment starting up for 128

128

the hundred is -= damage that's just being passed through when we call DealDamage. 129

129

And then we do our standard if did. 130

130

So if you think you know how to do this, 131

131

then just if the health gets below zero, destroy the game object. 132

132

Just complete that. 133

133

Okay, if health is <0, 134

134

then We will Destroy(gameObject). 135

135

So basically destroying me is what that means. 136

136

Whatever me is attached to, whatever this health has been placed onto. 137

137

So it's been reasonably good, save that up, jump back over into projectile. 138

138

Now, DealDamage, we have a mechanism for calling that. 139

139

How are we gonna do that, 140

140

well we know that when we collide with the particular thing. 141

141

The otherCollider, then at that instance we know who the otherCollider belongs to. 142

142

So we don't need to go searching through our entire project and say, 143

143

hang on a minute who did I just collide with I just collided with the thing 144

144

that owns the collider, so the otherCollider. 145

145

This could be called otherObject that currently possesses a collider, but 146

146

that's a bit too long. 147

147

So, let's start of by creating a variable, which we'll call var, 148

148

just a general variable. 149

149

var health = otherColider.GetComponent. 150

150

And component of type Health. 151

151

Now we have a reference to the health component or the health script, so 152

152

just remove my comments in here. 153

153

Then DealDamage, instead of just DealDamage, we're going to say 154

154

health.DealDamage, cuz we're referring to health which is our health component. 155

155

And DealDamage, I spelled it incorrectly there. 156

156

DealDamage, let me go back over into health and see what I code it. 157

157

DealDamage, and the problem is that I'm not passing anything in. 158

158

So it's saying we mass over it, it's saying there's no argument. 159

159

And that was because we said we need to know how much damage, so 160

160

thank you Visual Studio for reminding me of that. 161

161

How much damage, well, let's say we need something a serialized damage. 162

162

So we'll say damage in here, just kind of damage amount. 163

163

Up at the time [SerializeField] float damage. 164

164

Initialize that at, say, 50;. 165

165

Okay, now it's happy, it's passing, it's calling, hey, DealDamage, I want you to 166

166

give 50 points of damage, or whatever it's being changed to in the inspector. 167

167

Now, let's jump over and 168

168

see if we can get any mechanisms to see what's going on here. 169

169

Go to Console, clear our issues, click on Play. 170

170

Now, do we have a way to visualize what's going on? 171

171

Let's find whichever the first lizard is that comes out. 172

172

Let's grab them in our lane that is. 173

173

So this guy just here if I can click on New, 174

174

excellent, has health somewhere, we haven't added the health script. 175

175

What are we crazy? 176

176

That's what we are, we need to add the health script so 177

177

find your prefab of the lizard. 178

178

Click on Add Component, type in health. 179

179

Double click on that, I'll single click on that. 180

180

That is health, 100, yep that's fine. 181

181

Now let we click on Play, I'm gonna select one of the attackers that spawns. 182

182

This first, it was probably that guy, 183

183

they have already hit him that one, yep, there we go. 184

184

Already has 50 health. 185

185

That first Zucchini smacked into it and 186

186

then second time around, boom, health goes to 0. 187

187

Excellent, so we have cactus shooting projectiles that's damaging the lizard. 188

188

The lizard health is going down. 189

189

We've done that by creating our own trigger, 190

190

where we are calling the DealDamage and by having a mechanism that says as health, 191

191

as you're hit, then decrease your health until you get to 0. 192

192

And then I noticed one little bug which is the fact that we hit 0, so we twice 193

193

on 0 health but the attacker wasn't destroyed, and that's cuz we're saying <0. 194

194

So we need to say <=0. 195

195

We'll try that one more time, click on Play, 196

196

hopefully we hit this lizard, 197

197

it will be once, and then he did a second time, and it should disappear. 198

198

There we go, fantastic. 199

199

A few little bits and pieces we can tidy up but that is good for this video. 200

200

I think we got our core functionality in. 201

201

Let's put in a little bit more of that finesse in the next video. 202

202

So see you again shortly.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.