1
00:00:00,000 --> 00:00:00,000
Hello there.

2
00:00:00,000 --> 00:00:05,000
In this video, we're going to make invincibility for the player so he cannot be knocked twice in a

3
00:00:05,000 --> 00:00:05,000
row.

4
00:00:05,000 --> 00:00:06,000
How are we going to do that?

5
00:00:06,000 --> 00:00:07,000
Let's go to player.

6
00:00:07,000 --> 00:00:09,000
We're going to create a routine.

7
00:00:09,000 --> 00:00:12,000
What is quarantine is pretty simple to understand.

8
00:00:12,000 --> 00:00:15,000
Basically, it allows you to do some actions with a delay.

9
00:00:15,000 --> 00:00:17,000
How do you create a quarantine?

10
00:00:17,000 --> 00:00:26,000
You just go, let's say here and you make it private, a enumerator, you give it a name and our will

11
00:00:26,000 --> 00:00:32,000
be I'm not sure if I can spell it in win ability.

12
00:00:32,000 --> 00:00:34,000
Let me see if I spelled that correctly.

13
00:00:35,000 --> 00:00:35,000
Okay.

14
00:00:35,000 --> 00:00:37,000
This is the correct word.

15
00:00:37,000 --> 00:00:37,000
Yeah.

16
00:00:37,000 --> 00:00:39,000
Now how do we use it?

17
00:00:39,000 --> 00:00:40,000
Very simple.

18
00:00:40,000 --> 00:00:46,000
If we want to make some delay, we just make yield return new wait four.

19
00:00:46,000 --> 00:00:49,000
And here we can choose what we want and we want wait 4 seconds.

20
00:00:49,000 --> 00:00:54,000
And in our case, final is just choose point 5 seconds.

21
00:00:55,000 --> 00:01:02,000
So what I'm going to do debug dot log in wins started or and I'll choose let's say 5 seconds.

22
00:01:02,000 --> 00:01:10,000
All right then here I'll make delay of the 5 seconds and then I'll do the log in wins over.

23
00:01:11,000 --> 00:01:12,000
Now let's see, how does it work?

24
00:01:12,000 --> 00:01:15,000
How do we run this coverage in?

25
00:01:15,000 --> 00:01:17,000
We need just to do very simple stuff.

26
00:01:17,000 --> 00:01:20,000
We can type, start or routine.

27
00:01:20,000 --> 00:01:26,000
Now we need a name or we can just type in the instability here and it will work.

28
00:01:26,000 --> 00:01:26,000
Let's see.

29
00:01:26,000 --> 00:01:29,000
And now it's in the action.

30
00:01:29,000 --> 00:01:31,000
I'm going to open my console hit play.

31
00:01:31,000 --> 00:01:33,000
We're going to see first message.

32
00:01:33,000 --> 00:01:36,000
Then after 5 seconds, we're going to see another message.

33
00:01:38,000 --> 00:01:38,000
In.

34
00:01:38,000 --> 00:01:40,000
We started for five.

35
00:01:42,000 --> 00:01:47,000
In wins over and we can use it just to control bowl and can be knocked, for example.

36
00:01:47,000 --> 00:01:54,000
Let's go and create this boolean private bool can be knocked.

37
00:01:56,000 --> 00:01:57,000
Oh, sorry.

38
00:01:59,000 --> 00:02:07,000
Then we go in here and instead of using debug we're going to do can be knocked equals false.

39
00:02:09,000 --> 00:02:10,000
Can be knocked.

40
00:02:11,000 --> 00:02:12,000
Equals true.

41
00:02:16,000 --> 00:02:18,000
Now we don't start quarantine from here.

42
00:02:21,000 --> 00:02:28,000
We started in the knockback, so once player was knocked, we do start routine invincibility.

43
00:02:29,000 --> 00:02:35,000
And just above that, we're going to say, if not can be knocked, then return.

44
00:02:35,000 --> 00:02:35,000
Yes.

45
00:02:35,000 --> 00:02:36,000
So it can be knocked as false.

46
00:02:36,000 --> 00:02:40,000
Then we return from this function and none of this will work.

47
00:02:40,000 --> 00:02:41,000
And I guess we need to set.

48
00:02:41,000 --> 00:02:43,000
Can we knock to true by default?

49
00:02:43,000 --> 00:02:46,000
Let's go above and do this.

50
00:02:46,000 --> 00:02:47,000
I forgot to do that.

51
00:02:47,000 --> 00:02:49,000
Sorry can be not true.

52
00:02:50,000 --> 00:02:54,000
Now let's go back to Unity and see if I can knock back myself five times in a row.

53
00:02:54,000 --> 00:02:58,000
I can do it once, but not again until time passes.

54
00:03:01,000 --> 00:03:07,000
But if I would say not use this quarantine, I'll commit it out.

55
00:03:07,000 --> 00:03:08,000
Let's see what's going to happen.

56
00:03:12,000 --> 00:03:15,000
I can knock myself over and over again.

57
00:03:15,000 --> 00:03:18,000
And if there is a couple of traps, we can trigger it twice.

58
00:03:18,000 --> 00:03:19,000
So that's not what we need.

59
00:03:20,000 --> 00:03:22,000
All right, so let's uncomment this.

60
00:03:23,000 --> 00:03:28,000
Now we have invincibility, but it's not really clear if player is invincible.

61
00:03:28,000 --> 00:03:30,000
There is no obvious sign of that.

62
00:03:30,000 --> 00:03:35,000
So I want to do that and I want to do that in the style of very old games, how it was before.

63
00:03:36,000 --> 00:03:41,000
I want to make our sprite blink in the time of invincibility.

64
00:03:41,000 --> 00:03:42,000
Let me find the player.

65
00:03:42,000 --> 00:03:44,000
I'm going to open his color.

66
00:03:44,000 --> 00:03:48,000
And there is an Alpha channel which makes it transparent if we want.

67
00:03:48,000 --> 00:03:49,000
Right?

68
00:03:49,000 --> 00:03:52,000
So what I want to do is basically affects like this.

69
00:03:54,000 --> 00:04:01,000
We're going to change Alpha to half of the alpha and then back to original every 0.1 second.

70
00:04:01,000 --> 00:04:03,000
And it's going to look like this.

71
00:04:04,000 --> 00:04:04,000
Got it.

72
00:04:04,000 --> 00:04:06,000
So we're going to get access to a Sprite renderer.

73
00:04:06,000 --> 00:04:09,000
Then we're going to get access to the color and we're going to change.

74
00:04:09,000 --> 00:04:10,000
It's alpha.

75
00:04:12,000 --> 00:04:13,000
Okay, let's go and do that.

76
00:04:13,000 --> 00:04:14,000
Let's go back to code.

77
00:04:14,000 --> 00:04:19,000
We're going to need component of Sprite, Renderer, Private Sprite.

78
00:04:19,000 --> 00:04:20,000
Right, Renderer.

79
00:04:20,000 --> 00:04:22,000
And we're going to name it as S.r.

80
00:04:22,000 --> 00:04:28,000
Then we're going to go to start and assign this component S.R equals to get component of Sprite renderer.

81
00:04:29,000 --> 00:04:31,000
Then let's find our core routine.

82
00:04:31,000 --> 00:04:33,000
And where is it?

83
00:04:33,000 --> 00:04:34,000
Over here.

84
00:04:34,000 --> 00:04:36,000
We're going to make two temp values.

85
00:04:36,000 --> 00:04:43,000
First will be color, original color, which will be equals to our lot.

86
00:04:43,000 --> 00:04:45,000
Color, color of our sprite renderer.

87
00:04:45,000 --> 00:04:51,000
And then we're going to make another color darken color, which will be equals to new color.

88
00:04:51,000 --> 00:04:56,000
And color has four channels red, green, blue and alpha.

89
00:04:56,000 --> 00:05:01,000
We're going to take red of the original sprite renderer as our color dot are.

90
00:05:02,000 --> 00:05:03,000
Same for G.

91
00:05:05,000 --> 00:05:11,000
Same for blue as our color blue and for the alpha is going to be 0.5 like that.

92
00:05:12,000 --> 00:05:14,000
Now here, we said can be knocked to false.

93
00:05:14,000 --> 00:05:21,000
Of course, then we're going to control the color, as are color equals to darken color.

94
00:05:21,000 --> 00:05:25,000
Then we're going to wait for, let's say, 0.1 F.

95
00:05:26,000 --> 00:05:28,000
Then we're going to make S.r.

96
00:05:28,000 --> 00:05:32,000
I'll make a space here, as are color equals to original color.

97
00:05:33,000 --> 00:05:35,000
Then wait again 4.1 second.

98
00:05:36,000 --> 00:05:38,000
And this How is going to work?

99
00:05:38,000 --> 00:05:39,000
It's our color.

100
00:05:39,000 --> 00:05:40,000
Dark in color.

101
00:05:41,000 --> 00:05:44,000
We need to think how long we want invincibility to be.

102
00:05:44,000 --> 00:05:50,000
So lets say if it will be our one second, we need to combine values to make one second in total.

103
00:05:51,000 --> 00:05:52,000
So as our color.

104
00:05:54,000 --> 00:05:55,000
I can just copy this.

105
00:05:56,000 --> 00:05:57,000
Copy.

106
00:05:59,000 --> 00:05:59,000
Based.

107
00:06:00,000 --> 00:06:01,000
Based.

108
00:06:02,000 --> 00:06:02,000
Based.

109
00:06:02,000 --> 00:06:03,000
How long it is.

110
00:06:03,000 --> 00:06:07,000
One, two, three, four, five, six, seven, eight.

111
00:06:07,000 --> 00:06:08,000
To more.

112
00:06:09,000 --> 00:06:15,000
Then we set the original color and we make can be knocked through again and I can delete this line of

113
00:06:15,000 --> 00:06:15,000
code.

114
00:06:16,000 --> 00:06:21,000
So now, when instability not only sets can be knocked, but also changes color every point.

115
00:06:21,000 --> 00:06:22,000
One second.

116
00:06:22,000 --> 00:06:23,000
Let's try this.

117
00:06:24,000 --> 00:06:25,000
Let's see how it feels.

118
00:06:27,000 --> 00:06:28,000
Boom.

119
00:06:30,000 --> 00:06:33,000
We're blinking and we know that we are under some effect.

120
00:06:33,000 --> 00:06:38,000
And after a couple of tries, player will understand what is happening here because it's pretty intuitive.

121
00:06:38,000 --> 00:06:40,000
I only don't like how it looks.

122
00:06:40,000 --> 00:06:44,000
It's blinking kind of too fast, so maybe we can make it slower in the end.

123
00:06:44,000 --> 00:06:58,000
Let's go back to code and do this one one, then 1.5, 1.5 and then point 25 point 20.25, then point

124
00:06:58,000 --> 00:06:59,000
three.

125
00:06:59,000 --> 00:07:00,000
And then the original color.

126
00:07:00,000 --> 00:07:03,000
And we can delete these.

127
00:07:05,000 --> 00:07:08,000
So now we have less steps, but they take more time.

128
00:07:08,000 --> 00:07:09,000
Let's go and see this.

129
00:07:14,000 --> 00:07:16,000
Yeah, this looks better.

130
00:07:16,000 --> 00:07:19,000
This looks more intuitive and understandable.

131
00:07:19,000 --> 00:07:22,000
Something can fast in the beginning and then it gets in slower.

132
00:07:22,000 --> 00:07:25,000
And I have a feeling when it's going to be stopped.

133
00:07:25,000 --> 00:07:34,000
If you want, you can add a couple of more steps and just copy this, paste it in and make it longer.

134
00:07:34,000 --> 00:07:40,000
So point three, 5.4 I guess is going to be bit more clear.

135
00:07:41,000 --> 00:07:41,000
Boom.

136
00:07:44,000 --> 00:07:45,000
Yeah, that's.

137
00:07:46,000 --> 00:07:47,000
That feels good.

138
00:07:47,000 --> 00:07:48,000
I'll keep this one.

139
00:07:48,000 --> 00:07:50,000
All right, That's it for this video.

140
00:07:50,000 --> 00:07:51,000
See you in the next one.

