1
00:00:00,000 --> 00:00:03,360
Welcome back, My favorite game developers.

2
00:00:03,360 --> 00:00:06,650
In this video, we are going to become invincible.

3
00:00:06,645 --> 00:00:09,365
So now when we get shot once, the second time,

4
00:00:09,360 --> 00:00:10,560
we are invincible and you

5
00:00:10,560 --> 00:00:12,390
notice that we did a little flash,

6
00:00:12,390 --> 00:00:13,770
which is very cool.

7
00:00:13,770 --> 00:00:15,990
Now we are also going to become

8
00:00:15,990 --> 00:00:18,740
invincible when we do the torpedo.

9
00:00:18,735 --> 00:00:22,745
So nobody can hurt us while we are doing our torpedo.

10
00:00:22,740 --> 00:00:24,570
Obviously we didn't get there,

11
00:00:24,570 --> 00:00:26,430
but let's not worry about that.

12
00:00:26,430 --> 00:00:28,680
Let's first of all got to go and

13
00:00:28,680 --> 00:00:31,140
create our invincibility mechanics.

14
00:00:31,140 --> 00:00:32,770
So let's get started.

15
00:00:32,770 --> 00:00:34,460
O k.

16
00:00:34,460 --> 00:00:37,720
So now whenever we get shot,

17
00:00:37,715 --> 00:00:39,385
if we are, for example,

18
00:00:39,380 --> 00:00:43,010
caught up between the three skeletons right here,

19
00:00:43,010 --> 00:00:44,810
it might be just a little

20
00:00:44,810 --> 00:00:47,210
bit unfair for the player playing

21
00:00:47,210 --> 00:00:49,340
our game that he just dies

22
00:00:49,340 --> 00:00:52,070
immediately and doesn't even realize what happened.

23
00:00:52,070 --> 00:00:53,450
And another thing,

24
00:00:53,450 --> 00:00:55,640
a really nice thing that I would like to

25
00:00:55,640 --> 00:00:57,340
add as a game mechanic to our game

26
00:00:57,335 --> 00:00:59,445
is that whenever we are dashing,

27
00:00:59,449 --> 00:01:02,139
we have our player just a little bit

28
00:01:02,135 --> 00:01:03,865
invincible for a couple of

29
00:01:03,860 --> 00:01:06,140
seconds, maybe even milliseconds.

30
00:01:06,140 --> 00:01:07,930
So for that, we are going to

31
00:01:07,925 --> 00:01:09,775
implement this mechanic of having

32
00:01:09,770 --> 00:01:11,600
our player be invincible

33
00:01:11,600 --> 00:01:14,120
for at least a couple of seconds.

34
00:01:14,120 --> 00:01:16,940
So Let's go into our player health handler.

35
00:01:16,940 --> 00:01:20,390
And in here I'm going to create two variables.

36
00:01:20,390 --> 00:01:21,860
The first one is going to be

37
00:01:21,860 --> 00:01:25,220
a serialized field and it's going to be a float,

38
00:01:25,219 --> 00:01:29,449
and it's going to be the sensibility time.

39
00:01:29,450 --> 00:01:32,770
So how long does the player stay invincible?

40
00:01:32,765 --> 00:01:36,535
It's going to be added as a standard of 1 second.

41
00:01:36,530 --> 00:01:38,260
And then I'm going to create

42
00:01:38,255 --> 00:01:43,835
a private bool and call it the is invincible.

43
00:01:43,835 --> 00:01:46,265
So when the player is invincible,

44
00:01:46,265 --> 00:01:48,925
there are a couple of things that are going to happen

45
00:01:48,920 --> 00:01:51,620
and a couple of things that won't happen.

46
00:01:51,620 --> 00:01:53,960
And one of the things that won't happen is that

47
00:01:53,960 --> 00:01:56,890
the player will not take damage.

48
00:01:56,885 --> 00:01:59,425
So in here, we are going to

49
00:01:59,420 --> 00:02:02,050
check before we start damaging the player.

50
00:02:02,045 --> 00:02:05,185
If the player is invincible,

51
00:02:05,180 --> 00:02:08,630
then we are going to actually

52
00:02:08,630 --> 00:02:12,610
know what I meant to do is bow.

53
00:02:12,605 --> 00:02:16,715
So in here, let me remove this one.

54
00:02:16,715 --> 00:02:20,515
And, and an invitation to those.

55
00:02:20,510 --> 00:02:24,350
What I meant to say if the player is not invincible,

56
00:02:24,350 --> 00:02:26,360
so it's not invisible means we will

57
00:02:26,360 --> 00:02:29,050
add an exclamation mark behind this,

58
00:02:29,045 --> 00:02:31,705
and this will change the entire thing.

59
00:02:31,700 --> 00:02:33,680
So if he isn't invincible,

60
00:02:33,679 --> 00:02:35,659
is invincible is true,

61
00:02:35,660 --> 00:02:37,640
which means the whole condition

62
00:02:37,640 --> 00:02:39,770
is false because of the exclamation mark,

63
00:02:39,770 --> 00:02:41,720
this means we do not access this.

64
00:02:41,720 --> 00:02:44,340
This means whenever we are invincible,

65
00:02:44,344 --> 00:02:45,804
is invincible is true.

66
00:02:45,800 --> 00:02:47,800
We do not get hurt.

67
00:02:47,795 --> 00:02:49,085
So excellent.

68
00:02:49,085 --> 00:02:50,435
Let's continue on.

69
00:02:50,435 --> 00:02:52,045
The next thing we want to do is

70
00:02:52,040 --> 00:02:53,870
we want to make sure that we

71
00:02:53,870 --> 00:02:55,970
then stop being invincible

72
00:02:55,970 --> 00:02:57,610
after a certain amount of time.

73
00:02:57,605 --> 00:03:01,005
So for that we are going to have to create a coating.

74
00:03:01,009 --> 00:03:04,389
So I'm going to issue it to you as a challenge.

75
00:03:04,385 --> 00:03:07,375
So turn the player back using a coating.

76
00:03:07,370 --> 00:03:09,380
You'll need to create a core thing that turns

77
00:03:09,380 --> 00:03:11,710
the player back from his invincibility,

78
00:03:11,705 --> 00:03:15,155
should use the invincibility time variable

79
00:03:15,155 --> 00:03:16,945
and you need to call the coating

80
00:03:16,940 --> 00:03:18,770
in the appropriate place.

81
00:03:18,770 --> 00:03:22,100
So with that information of the video right now,

82
00:03:22,100 --> 00:03:24,810
and go to the challenge.

83
00:03:24,810 --> 00:03:26,620
Okay, welcome back.

84
00:03:26,620 --> 00:03:28,240
How did you get on with that?

85
00:03:28,240 --> 00:03:29,980
You know, what I love about

86
00:03:29,980 --> 00:03:32,470
the challenges is that it keeps you accountable.

87
00:03:32,470 --> 00:03:35,340
So if at this point you still did not

88
00:03:35,335 --> 00:03:38,525
know how a court in works after all the challenges,

89
00:03:38,529 --> 00:03:41,529
you will have to learn at some point because I will

90
00:03:41,530 --> 00:03:42,940
keep asking you to do

91
00:03:42,940 --> 00:03:45,400
something until it is ingrained in you.

92
00:03:45,400 --> 00:03:48,610
So let's take it easy bit and

93
00:03:48,610 --> 00:03:52,150
let's go ahead and create an eye enumerator in here.

94
00:03:52,150 --> 00:03:54,370
So I believe it's pretty easy now.

95
00:03:54,370 --> 00:03:57,910
So it's player is invincible.

96
00:03:57,910 --> 00:04:04,380
Or turn back to what should we call this layer?

97
00:04:04,375 --> 00:04:10,285
Let's just call it is in invincible.

98
00:04:10,280 --> 00:04:13,130
They, they're not invincible.

99
00:04:13,129 --> 00:04:15,099
Okay, Let's call it that.

100
00:04:15,095 --> 00:04:17,515
And here we are going to yield

101
00:04:17,510 --> 00:04:21,760
return new weight for second.

102
00:04:21,755 --> 00:04:22,985
I mean, by this point,

103
00:04:22,985 --> 00:04:25,835
it should be like just sneezing or breathing.

104
00:04:25,835 --> 00:04:27,985
So we yield return new wait

105
00:04:27,980 --> 00:04:31,220
four seconds, the invincibility time.

106
00:04:31,219 --> 00:04:33,769
And after that invincibility time is

107
00:04:33,770 --> 00:04:37,010
invincible will be back to false.

108
00:04:37,010 --> 00:04:39,890
And also I want to make sure that as soon as we

109
00:04:39,890 --> 00:04:43,540
start the is invincible is set to false.

110
00:04:43,535 --> 00:04:45,715
So that we are not

111
00:04:45,710 --> 00:04:48,260
invincible as soon as we start with that done,

112
00:04:48,260 --> 00:04:50,390
I believe that's everything that we need to do.

113
00:04:50,390 --> 00:04:51,710
So I'm going to save this.

114
00:04:51,710 --> 00:04:53,800
I'm going to go back into our game.

115
00:04:53,795 --> 00:04:55,795
And let's run the game.

116
00:04:55,790 --> 00:04:57,440
And let's see what happens.

117
00:04:57,440 --> 00:04:59,530
So when i, okay, so first off,

118
00:04:59,525 --> 00:05:01,985
we need to add maybe a couple of more seconds.

119
00:05:01,985 --> 00:05:04,255
So doom and sensibility time,

120
00:05:04,250 --> 00:05:08,330
let's make it two, and let's run it again.

121
00:05:08,330 --> 00:05:10,480
So this will be the time.

122
00:05:10,475 --> 00:05:12,145
So we get hit once.

123
00:05:12,140 --> 00:05:15,100
There we go. Now we get it twice, we still die.

124
00:05:15,095 --> 00:05:16,495
Why is that?

125
00:05:16,490 --> 00:05:18,140
Let's see what the problem is.

126
00:05:18,140 --> 00:05:20,630
Let's make this public so we can see

127
00:05:20,630 --> 00:05:23,680
clearly if we are actually changing what's happening.

128
00:05:23,675 --> 00:05:26,815
All we haven't started the cold in here.

129
00:05:26,810 --> 00:05:29,530
So I'm going to make sure that we do.

130
00:05:29,525 --> 00:05:32,425
In here, Where should we call it 0?

131
00:05:32,420 --> 00:05:39,920
So also what I want to do is whenever we do get hit,

132
00:05:39,920 --> 00:05:44,180
we also need to change the is invincible to true.

133
00:05:44,180 --> 00:05:46,520
So there are many steps that I forgot to do.

134
00:05:46,520 --> 00:05:47,890
And after we get it,

135
00:05:47,885 --> 00:05:50,725
I'm going to start the co-routine.

136
00:05:50,720 --> 00:05:56,660
And the coroutine will be the layer, not invincible.

137
00:05:56,660 --> 00:05:58,430
So there are a lot of things.

138
00:05:58,430 --> 00:06:00,640
So let me tell you what I forgot to do.

139
00:06:00,635 --> 00:06:02,735
And here, as soon as we get hit,

140
00:06:02,735 --> 00:06:05,855
we want to set the invincible to true.

141
00:06:05,855 --> 00:06:07,555
And once we are invincible,

142
00:06:07,550 --> 00:06:09,440
we are then going to start the coroutine.

143
00:06:09,440 --> 00:06:11,750
And because the is invincible is true,

144
00:06:11,750 --> 00:06:13,220
we no longer get damaged.

145
00:06:13,220 --> 00:06:15,290
So this line was crucial.

146
00:06:15,290 --> 00:06:17,240
And I don't even know how I

147
00:06:17,240 --> 00:06:19,340
could have forgot something so important,

148
00:06:19,340 --> 00:06:20,810
this is the whole essence of

149
00:06:20,810 --> 00:06:22,400
making our player invincible.

150
00:06:22,400 --> 00:06:24,400
So I hope you understand what's happening.

151
00:06:24,395 --> 00:06:25,765
I hope you're not too mad of

152
00:06:25,760 --> 00:06:28,070
the mistakes that I sometimes make.

153
00:06:28,070 --> 00:06:29,950
And let's go ahead and run the game.

154
00:06:29,945 --> 00:06:32,815
So there we go, we get hit once, we get it twice.

155
00:06:32,810 --> 00:06:33,230
There you go.

156
00:06:33,230 --> 00:06:36,130
You can see that the second hip did not kill us.

157
00:06:36,125 --> 00:06:39,685
Why? Because we had the invincibility time on.

158
00:06:39,680 --> 00:06:41,830
So we can see right here it was on.

159
00:06:41,825 --> 00:06:44,845
Let's test this out again because I

160
00:06:44,840 --> 00:06:47,990
feel that we should have maybe taken one more hit.

161
00:06:47,990 --> 00:06:53,050
So there we go is invincible and we died.

162
00:06:53,045 --> 00:06:55,855
I still feel that there's something not

163
00:06:55,850 --> 00:07:00,170
quite wrong and I'm quite right. So 50.

164
00:07:00,170 --> 00:07:04,160
So let's make sure that it's working.

165
00:07:04,160 --> 00:07:06,320
Let's set it to maybe five seconds

166
00:07:06,320 --> 00:07:08,710
and see if that lasts longer.

167
00:07:08,705 --> 00:07:10,555
Because I can see in here that this is

168
00:07:10,550 --> 00:07:15,050
not changing 1234, okay,

169
00:07:15,050 --> 00:07:17,590
so I know I think everything is working,

170
00:07:17,585 --> 00:07:19,465
but for some reason we aren't

171
00:07:19,460 --> 00:07:21,470
seeing this change right here.

172
00:07:21,470 --> 00:07:22,940
But no worries about that.

173
00:07:22,940 --> 00:07:25,420
We know that it's working because when we

174
00:07:25,415 --> 00:07:28,595
increase the size of the time, we are invincible.

175
00:07:28,595 --> 00:07:32,345
We can stand on the face of the sort a bit longer.

176
00:07:32,345 --> 00:07:35,425
Okay, great. Now, that is all fine and dandy.

177
00:07:35,420 --> 00:07:36,940
But here is the problem.

178
00:07:36,935 --> 00:07:38,875
We have no idea that we are

179
00:07:38,870 --> 00:07:41,090
invincible for a certain amount of time.

180
00:07:41,090 --> 00:07:43,130
So what we're going to do is we are going

181
00:07:43,130 --> 00:07:45,310
to try to visualize this.

182
00:07:45,305 --> 00:07:46,535
So do that.

183
00:07:46,535 --> 00:07:48,745
What I think I'll do is

184
00:07:48,740 --> 00:07:51,170
I'm going to access the body right here.

185
00:07:51,170 --> 00:07:54,620
You can see that we have the colors and when we get hit,

186
00:07:54,620 --> 00:07:57,230
I'm going to make the player blink.

187
00:07:57,230 --> 00:08:00,320
So I'll make him blink once, twice, three times,

188
00:08:00,320 --> 00:08:05,120
or keep a blinking until the time that we have is over.

189
00:08:05,120 --> 00:08:08,110
So Let's go ahead and do that.

190
00:08:08,105 --> 00:08:11,365
So I'm going to go in here and I'm going

191
00:08:11,360 --> 00:08:14,920
to get a reference to the sprite of the player.

192
00:08:14,915 --> 00:08:18,365
So serialized field.

193
00:08:18,365 --> 00:08:23,555
And it's going to be the sprite renderer.

194
00:08:23,555 --> 00:08:27,115
And it's going to be the player sprite.

195
00:08:27,110 --> 00:08:30,110
There we go. And in here we are going

196
00:08:30,110 --> 00:08:32,980
to create a numerator.

197
00:08:32,975 --> 00:08:36,155
And it's going to be the flasher.

198
00:08:36,155 --> 00:08:40,085
And in here what we'll do is we are going to,

199
00:08:40,085 --> 00:08:41,455
first of all determine how many

200
00:08:41,450 --> 00:08:42,890
flashes do we want to have.

201
00:08:42,890 --> 00:08:45,580
And then we'll create a for loop.

202
00:08:45,575 --> 00:08:46,345
Wait for it.

203
00:08:46,340 --> 00:08:48,290
You know what I'm talking about?

204
00:08:48,290 --> 00:08:51,910
It's going to have the int equals 0,

205
00:08:51,905 --> 00:08:55,715
while I is less than how many flashes do we want?

206
00:08:55,715 --> 00:08:57,815
Let's say five flashes.

207
00:08:57,814 --> 00:09:00,004
And I plus, plus.

208
00:09:00,005 --> 00:09:00,955
Okay.

209
00:09:00,950 --> 00:09:02,470
So stay with me.

210
00:09:02,465 --> 00:09:04,675
I'm going to leave you properly.

211
00:09:04,670 --> 00:09:06,620
I'm going to first of all add a bit

212
00:09:06,620 --> 00:09:08,690
of spacing in here and then I'm

213
00:09:08,690 --> 00:09:12,100
going to access the player sprite dot color

214
00:09:12,095 --> 00:09:15,655
is going to be equal to a new color.

215
00:09:15,650 --> 00:09:19,550
Open up the brackets or whatever they are called.

216
00:09:19,550 --> 00:09:21,760
And then I'm going to write in here,

217
00:09:21,755 --> 00:09:25,705
we will keep the a the same.

218
00:09:25,840 --> 00:09:28,560
We will keep the,

219
00:09:28,564 --> 00:09:31,164
let me just duplicate this line twice.

220
00:09:31,160 --> 00:09:32,420
We will keep the a.

221
00:09:32,420 --> 00:09:33,940
Then we have the ordinal.

222
00:09:33,935 --> 00:09:36,245
We start off by red,

223
00:09:36,245 --> 00:09:41,125
red, green, and blue.

224
00:09:41,120 --> 00:09:42,980
And finally, we will have

225
00:09:42,980 --> 00:09:45,730
the last one which should not take a comma.

226
00:09:45,725 --> 00:09:48,505
Can see right here we don't have a comma and it's going

227
00:09:48,500 --> 00:09:51,320
to be the, the a.

228
00:09:51,320 --> 00:09:52,940
But in our case, first of all,

229
00:09:52,940 --> 00:09:54,290
we want to reduce the a.

230
00:09:54,290 --> 00:09:57,900
So let's set it to maybe 0.1.

231
00:09:58,570 --> 00:10:06,010
Then after this, we are going to yield return new.

232
00:10:06,005 --> 00:10:08,975
And we are going to wait four seconds.

233
00:10:08,975 --> 00:10:11,515
And this is how fast we are going to be blinking.

234
00:10:11,510 --> 00:10:14,200
So I'm going to set it to your 0.1.

235
00:10:14,195 --> 00:10:17,065
When we don't have a 0 or just a point,

236
00:10:17,060 --> 00:10:18,710
that means we have 0.1.

237
00:10:18,710 --> 00:10:22,690
It's just a bit of a faster way to do things.

238
00:10:22,685 --> 00:10:25,315
And then we are going to go back and copy

239
00:10:25,310 --> 00:10:27,760
this line and put it in here.

240
00:10:27,755 --> 00:10:29,665
And instead of 0.1,

241
00:10:29,660 --> 00:10:31,570
we were going to have the one.

242
00:10:31,565 --> 00:10:33,895
And let me just add a tab

243
00:10:33,890 --> 00:10:36,230
in here for implementation purposes.

244
00:10:36,230 --> 00:10:38,060
So just understand everything.

245
00:10:38,060 --> 00:10:40,960
And then we are again going to

246
00:10:40,955 --> 00:10:44,575
yield weight return for 1. Second.

247
00:10:44,570 --> 00:10:45,580
Save that.

248
00:10:45,575 --> 00:10:48,205
And now we have to start the coroutine somewhere.

249
00:10:48,200 --> 00:10:50,030
When we get hit right

250
00:10:50,030 --> 00:10:52,390
after we set the invincibility to true,

251
00:10:52,385 --> 00:10:54,805
are going to start the co-routine,

252
00:10:54,800 --> 00:11:01,190
which is going to be V flasher with the parentheses also,

253
00:11:01,190 --> 00:11:03,380
these are called parenthesis, I just remembered.

254
00:11:03,380 --> 00:11:05,540
Maybe they'll carpool and parentheses and ways we

255
00:11:05,540 --> 00:11:07,750
save that what is happening in here.

256
00:11:07,745 --> 00:11:09,665
So first of all, we have the loop.

257
00:11:09,665 --> 00:11:13,135
We already know how the loop works. We start off at 0.

258
00:11:13,130 --> 00:11:14,440
We do it four times,

259
00:11:14,435 --> 00:11:15,865
five times actually is 4,

260
00:11:15,860 --> 00:11:18,070
0, 1, 2, 3, and 4.

261
00:11:18,065 --> 00:11:20,305
So 5 times, we increase by one

262
00:11:20,300 --> 00:11:22,750
every single time and we'll loop through.

263
00:11:22,745 --> 00:11:24,595
So what are we doing in here?

264
00:11:24,590 --> 00:11:26,260
We are changing the color.

265
00:11:26,255 --> 00:11:27,925
We keep everything the red, green,

266
00:11:27,920 --> 00:11:30,440
and blue the same except for the alpha.

267
00:11:30,440 --> 00:11:32,390
And in here we are doing the same.

268
00:11:32,390 --> 00:11:36,320
So the first one we are reducing to alpha to 0.1.

269
00:11:36,320 --> 00:11:39,550
And the second one we are making the Alpha 1.

270
00:11:39,545 --> 00:11:41,455
And what are we doing in here?

271
00:11:41,450 --> 00:11:43,460
Well, we already know how yield

272
00:11:43,460 --> 00:11:46,390
return you wait four seconds works.

273
00:11:46,385 --> 00:11:49,925
First of all, we have the alpha at 0.1.

274
00:11:49,925 --> 00:11:52,445
We wait for 0.1 seconds.

275
00:11:52,445 --> 00:11:54,545
Then we turn it back to one.

276
00:11:54,545 --> 00:11:57,275
We wait for 0.1 seconds and then

277
00:11:57,275 --> 00:12:00,535
again start the loop and we keep doing this.

278
00:12:00,530 --> 00:12:03,730
So we'll go, okay,

279
00:12:03,725 --> 00:12:05,485
and we keep doing this and this will

280
00:12:05,480 --> 00:12:07,510
create a flashing effect,

281
00:12:07,505 --> 00:12:09,695
not believe me, that's that out.

282
00:12:09,695 --> 00:12:11,705
So I'm going to go back in here.

283
00:12:11,705 --> 00:12:16,565
I'm going to run the game and let's see what happens.

284
00:12:16,565 --> 00:12:18,955
So I'm going to approach the enemy.

285
00:12:18,950 --> 00:12:22,060
He shoots me and nothing happens because obviously,

286
00:12:22,055 --> 00:12:23,815
every single time we have to make

287
00:12:23,810 --> 00:12:27,700
the same mistake that we need to add the player sprite.

288
00:12:27,695 --> 00:12:29,695
Then we drag the body,

289
00:12:29,690 --> 00:12:30,770
we save all of that.

290
00:12:30,770 --> 00:12:34,540
We going to apply the changes and we're going to run.

291
00:12:34,535 --> 00:12:39,595
And now we should see that we, There we go.

292
00:12:39,590 --> 00:12:41,060
You can see that we start blinking.

293
00:12:41,060 --> 00:12:42,350
When we stop blinking,

294
00:12:42,350 --> 00:12:44,890
that means that we are no longer invincible.

295
00:12:44,885 --> 00:12:47,615
Now the only thing here, the only trick,

296
00:12:47,615 --> 00:12:50,335
tricky thing here is that we want to make

297
00:12:50,330 --> 00:12:53,450
sure that the invincibility time and the flushing

298
00:12:53,450 --> 00:12:55,610
coincide so we don't start

299
00:12:55,610 --> 00:12:58,550
flashing and then for some reason we

300
00:12:58,550 --> 00:13:01,250
stop flashing yet we are still

301
00:13:01,250 --> 00:13:04,210
invincible or the other way around we keep flashing,

302
00:13:04,205 --> 00:13:06,655
but we are no longer invincible so we die.

303
00:13:06,650 --> 00:13:07,730
We're not sure what's happening.

304
00:13:07,730 --> 00:13:09,590
So there will be a bit of

305
00:13:09,590 --> 00:13:11,270
a timing issue that you'll need

306
00:13:11,270 --> 00:13:13,040
to tweak around and make sure it works.

307
00:13:13,040 --> 00:13:14,800
But with that said,

308
00:13:14,795 --> 00:13:18,155
I'm going to issue you an extra challenge.

309
00:13:18,155 --> 00:13:19,445
How cool is that?

310
00:13:19,445 --> 00:13:21,685
I am 100% sure you did not see

311
00:13:21,680 --> 00:13:23,900
that coming because I want to make

312
00:13:23,900 --> 00:13:26,150
the player invincible when he does

313
00:13:26,150 --> 00:13:29,410
the torpedo or the dash or whatever you call it.

314
00:13:29,405 --> 00:13:33,295
So that information, pause the video right now

315
00:13:33,290 --> 00:13:35,260
and make the player also

316
00:13:35,255 --> 00:13:38,015
invincible when he does the torpedo.

317
00:13:38,015 --> 00:13:40,225
Oh, okay, welcome back.

318
00:13:40,220 --> 00:13:42,850
So what are we going to do in here?

319
00:13:42,845 --> 00:13:45,545
Obviously, we have the flasher right here,

320
00:13:45,545 --> 00:13:47,495
but we want to make sure that we

321
00:13:47,495 --> 00:13:49,375
call it from another method,

322
00:13:49,370 --> 00:13:51,190
which is the player controller.

323
00:13:51,185 --> 00:13:53,125
When we are, Where is it,

324
00:13:53,120 --> 00:13:56,390
Where is it switching gun? The player dashing.

325
00:13:56,390 --> 00:13:57,490
So there we go in here,

326
00:13:57,485 --> 00:13:59,065
we want to make sure that we call

327
00:13:59,060 --> 00:14:00,740
this whenever we are dashing,

328
00:14:00,740 --> 00:14:02,600
how are we going to do this?

329
00:14:02,600 --> 00:14:03,800
Well, it's pretty easy.

330
00:14:03,800 --> 00:14:05,470
We need to start a co-routine.

331
00:14:05,465 --> 00:14:08,005
So we are going to look back in here.

332
00:14:08,000 --> 00:14:09,800
Do we have a coroutine?

333
00:14:09,800 --> 00:14:12,200
We are going to go ahead and get

334
00:14:12,200 --> 00:14:16,090
the component, the player health.

335
00:14:16,085 --> 00:14:19,975
Whereas it layer handler.

336
00:14:19,970 --> 00:14:20,980
There we go.

337
00:14:20,975 --> 00:14:23,245
And in here we are going to,

338
00:14:23,240 --> 00:14:27,200
before we get the component, start a coroutine.

339
00:14:27,200 --> 00:14:33,730
And I think because this one is what's the name?

340
00:14:33,725 --> 00:14:38,485
And just check on No,

341
00:14:38,480 --> 00:14:40,850
Actually, sorry for that.

342
00:14:40,850 --> 00:14:43,490
Dot start coroutine.

343
00:14:43,490 --> 00:14:46,290
And here we are going to access the flasher.

344
00:14:46,294 --> 00:14:53,344
Can we know we need to make it a public on enumerator.

345
00:14:53,345 --> 00:14:58,625
So flasher, it's not allowing me to.

346
00:14:58,625 --> 00:15:07,775
Okay, So I think we have to do it like this.

347
00:15:07,775 --> 00:15:10,445
So start coroutine.

348
00:15:11,290 --> 00:15:14,540
And there we go.

349
00:15:14,540 --> 00:15:15,640
Save that.

350
00:15:15,635 --> 00:15:17,125
So as you can see,

351
00:15:17,120 --> 00:15:19,610
even I wasn't sure how this is going to work,

352
00:15:19,610 --> 00:15:22,250
but apparently we need to start the coroutine.

353
00:15:22,250 --> 00:15:23,750
We access the component,

354
00:15:23,750 --> 00:15:27,130
we get the player health handler and NBA player handler.

355
00:15:27,125 --> 00:15:28,675
We get the flasher.

356
00:15:28,670 --> 00:15:29,860
So save that.

357
00:15:29,855 --> 00:15:31,835
Let's test this out.

358
00:15:31,835 --> 00:15:33,785
Back in our game.

359
00:15:33,785 --> 00:15:35,245
We run the game.

360
00:15:35,240 --> 00:15:38,510
And now when we do the dash, there we go.

361
00:15:38,510 --> 00:15:40,240
You can see that we are flashing.

362
00:15:40,235 --> 00:15:42,535
How cool is that an phi dash?

363
00:15:42,530 --> 00:15:44,380
We should see that I don't get,

364
00:15:44,375 --> 00:15:46,735
okay, So that didn't work.

365
00:15:46,730 --> 00:15:48,350
Let's not worry about that.

366
00:15:48,350 --> 00:15:50,330
It's going to be hard maybe to time

367
00:15:50,330 --> 00:15:53,810
the time we are invisible with the dashing,

368
00:15:53,810 --> 00:15:57,250
with having the enemies shooters.

369
00:15:57,245 --> 00:15:58,615
Don't worry about that because

370
00:15:58,610 --> 00:16:00,170
in the next video we are going

371
00:16:00,170 --> 00:16:03,290
to be creating some spikes traps.

372
00:16:03,290 --> 00:16:05,510
And this is a great way to test

373
00:16:05,510 --> 00:16:08,090
out our invincibility when we're dashing.

374
00:16:08,090 --> 00:16:10,700
So if we walk through the sprites will die.

375
00:16:10,700 --> 00:16:14,060
If we walk through the sprites While dashing,

376
00:16:14,059 --> 00:16:16,509
we will not die because we will be invincible.

377
00:16:16,505 --> 00:16:17,815
So that's said.

378
00:16:17,810 --> 00:16:20,990
There is also one more thing that even though we are

379
00:16:20,990 --> 00:16:24,440
flashing in here on the player controller,

380
00:16:24,440 --> 00:16:26,110
we are not invincible.

381
00:16:26,105 --> 00:16:28,585
And make the player invincible was the challenge,

382
00:16:28,580 --> 00:16:31,420
and I just noticed that before we turned everything off.

383
00:16:31,415 --> 00:16:33,625
So to avoid the confusion,

384
00:16:33,620 --> 00:16:37,700
what I'm going to do is back and the where are we,

385
00:16:37,700 --> 00:16:39,500
the player health handler.

386
00:16:39,500 --> 00:16:41,750
I'm going to create a method which

387
00:16:41,750 --> 00:16:44,170
don't be a public void.

388
00:16:44,165 --> 00:16:50,335
Make layer in sensible what was not invisible,

389
00:16:50,330 --> 00:16:53,590
okay, make their invent symbol.

390
00:16:53,585 --> 00:16:55,945
And in here I'm going to first

391
00:16:55,940 --> 00:16:57,890
of all turn the invincibility on.

392
00:16:57,890 --> 00:17:03,700
So is as and invincible will be equal to true.

393
00:17:03,695 --> 00:17:06,025
Then we are going to

394
00:17:06,020 --> 00:17:09,600
start the coroutine of the flash one.

395
00:17:11,680 --> 00:17:17,100
And finally, we are also going to start the coating.

396
00:17:18,310 --> 00:17:22,790
Please, let me start courting of

397
00:17:22,790 --> 00:17:26,840
the make to what was it called?

398
00:17:26,840 --> 00:17:28,990
Player not invincible.

399
00:17:28,985 --> 00:17:33,005
Player not invincible.

400
00:17:33,005 --> 00:17:36,665
So now we have one method that does everything,

401
00:17:36,665 --> 00:17:38,525
one method to rule them all.

402
00:17:38,525 --> 00:17:41,405
So we can remove this one from here.

403
00:17:41,405 --> 00:17:44,305
We can remove the flasher and the true.

404
00:17:44,300 --> 00:17:47,510
And we can do one thing and that is called

405
00:17:47,510 --> 00:17:50,860
the make player invincible,

406
00:17:50,855 --> 00:17:54,265
save that, and then end the player controller.

407
00:17:54,260 --> 00:17:57,350
We don't need to call the flasher manually.

408
00:17:57,350 --> 00:18:01,340
We can just say Get Component,

409
00:18:01,340 --> 00:18:08,030
Layer health handler, dot, make, player invincible.

410
00:18:08,030 --> 00:18:09,080
There we go.

411
00:18:09,080 --> 00:18:11,110
So let's test this out again.

412
00:18:11,105 --> 00:18:14,125
Back in our game, run the game.

413
00:18:14,120 --> 00:18:15,850
Should us.

414
00:18:15,845 --> 00:18:17,525
We can't shut once.

415
00:18:17,525 --> 00:18:19,765
We got shot twice and we died.

416
00:18:19,760 --> 00:18:21,520
What is the problem?

417
00:18:21,515 --> 00:18:23,305
Did we make it only 1 second?

418
00:18:23,300 --> 00:18:25,580
Let's make it through R3.

419
00:18:25,580 --> 00:18:28,210
Three seconds, run the game.

420
00:18:28,205 --> 00:18:29,675
Again.

421
00:18:29,675 --> 00:18:33,985
We get shot once, twice, three times.

422
00:18:33,980 --> 00:18:35,150
Okay, so this is working.

423
00:18:35,150 --> 00:18:37,570
And then when we do the dash, there we go.

424
00:18:37,565 --> 00:18:39,395
We are dashing.

425
00:18:39,395 --> 00:18:41,395
Okay, we didn't test it out properly.

426
00:18:41,390 --> 00:18:43,510
In the next video, we will make sure of that.

427
00:18:43,505 --> 00:18:45,665
I'm sorry for the length of the video.

428
00:18:45,665 --> 00:18:48,175
Again, this is something good.

429
00:18:48,170 --> 00:18:49,790
I believe we learned how to

430
00:18:49,790 --> 00:18:51,830
start a coroutine from a different script.

431
00:18:51,830 --> 00:18:53,870
And we also learned how to create

432
00:18:53,870 --> 00:18:57,250
a method and compact everything into a single place.

433
00:18:57,245 --> 00:18:58,765
I think it's good,

434
00:18:58,760 --> 00:19:00,110
a good habit to them.

435
00:19:00,110 --> 00:19:01,670
So thank you so much for watching.

436
00:19:01,670 --> 00:19:02,780
I hope you are enjoying,

437
00:19:02,780 --> 00:19:04,220
I hope you're committing your changes.

438
00:19:04,220 --> 00:19:06,230
And I'll see you in the next video where

439
00:19:06,230 --> 00:19:08,330
we will be creating spikes.

440
00:19:08,330 --> 00:19:12,000
We also had an extra challenge which is very good.

