1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:07,000
In this video, we're going to change color of the platforms and that will be our last features before

3
00:00:07,000 --> 00:00:08,000
we make level parts.

4
00:00:08,000 --> 00:00:08,000
I guess.

5
00:00:08,000 --> 00:00:10,000
So what are we going to do here?

6
00:00:10,000 --> 00:00:13,000
Basically something very simple we're going to use on trigger enter.

7
00:00:13,000 --> 00:00:18,000
We're going to get access to component of the sprite renderer and on trigger enter.

8
00:00:18,000 --> 00:00:19,000
We're going to change color.

9
00:00:19,000 --> 00:00:23,000
So I guess you know what to do now and you can try to do it as a challenge.

10
00:00:23,000 --> 00:00:24,000
All right.

11
00:00:24,000 --> 00:00:25,000
Go and try to do that.

12
00:00:25,000 --> 00:00:28,000
So when you step on the platform, you change the color of the platform.

13
00:00:28,000 --> 00:00:32,000
You have a couple of seconds before I continue and show what to do.

14
00:00:32,000 --> 00:00:34,000
One, two, three.

15
00:00:35,000 --> 00:00:41,000
So what we do here, I'm going to take my level part and I did delete traps because I want to have an

16
00:00:41,000 --> 00:00:42,000
easy test in here.

17
00:00:44,000 --> 00:00:45,000
Let's take the platform.

18
00:00:45,000 --> 00:00:50,000
I'm going to create empty object under the platform and I'm going to call it body.

19
00:00:50,000 --> 00:00:53,000
Then I'm going to add component of Box Collider.

20
00:00:54,000 --> 00:00:57,000
And now whenever I change size of the platform.

21
00:00:58,000 --> 00:01:03,000
I changed scale of the platform to any size I want Collider of my body going to have same size.

22
00:01:03,000 --> 00:01:08,000
So we have nothing to worry about when we change platform and now we can take a leader of the parent

23
00:01:08,000 --> 00:01:10,000
over here and make it A's trigger.

24
00:01:11,000 --> 00:01:11,000
All right.

25
00:01:13,000 --> 00:01:13,000
It is done.

26
00:01:14,000 --> 00:01:16,000
Now let's go and add component.

27
00:01:16,000 --> 00:01:17,000
New script.

28
00:01:19,000 --> 00:01:21,000
Platform.

29
00:01:22,000 --> 00:01:23,000
Controller.

30
00:01:23,000 --> 00:01:30,000
I guess now what I'm going to do here first is to get access to Sprite Renderer Serialize Field.

31
00:01:31,000 --> 00:01:36,000
By what bright renderer S.r At this time I don't want to do it in the start.

32
00:01:36,000 --> 00:01:38,000
I'll just do it in the inspector as well.

33
00:01:38,000 --> 00:01:39,000
I do need an update.

34
00:01:40,000 --> 00:01:42,000
And now on trigger enter to DD.

35
00:01:43,000 --> 00:01:46,000
You're going to check if collision happens with the player.

36
00:01:46,000 --> 00:01:54,000
So if collision dot get component of a player not equals to null, then we take S.R, dot color equals

37
00:01:54,000 --> 00:01:56,000
two and we're going to assign new color.

38
00:01:56,000 --> 00:01:59,000
And as of now we don't have any color shop or anything.

39
00:01:59,000 --> 00:02:03,000
I'm just going to write color dot white just for testing.

40
00:02:03,000 --> 00:02:04,000
Let's go there now.

41
00:02:04,000 --> 00:02:07,000
I'm going to drag my Sprite renderer over here.

42
00:02:08,000 --> 00:02:09,000
And going to go back.

43
00:02:09,000 --> 00:02:11,000
I'll let me check my endpoint.

44
00:02:11,000 --> 00:02:14,000
Well, it can be a bit further, so we have to jump sometimes.

45
00:02:17,000 --> 00:02:20,000
Now, look, I step on the platform and I change colour of the platform.

46
00:02:24,000 --> 00:02:28,000
Now, first question, What if you want to have different color, not white?

47
00:02:28,000 --> 00:02:31,000
We're going to purchase colors from the shop that we're going to create later.

48
00:02:31,000 --> 00:02:35,000
As of now, let's just create a variable in the game manager.

49
00:02:36,000 --> 00:02:37,000
Mhm.

50
00:02:37,000 --> 00:02:39,000
Public color.

51
00:02:41,000 --> 00:02:43,000
Lot form color.

52
00:02:44,000 --> 00:02:46,000
And in the platform controller instead of white.

53
00:02:46,000 --> 00:02:48,000
We're going to do game manager.

54
00:02:48,000 --> 00:02:50,000
That instance, that platform color.

55
00:02:50,000 --> 00:02:55,000
See, that was I was talking about when I was saying we need a game manager that we can use as a hub

56
00:02:55,000 --> 00:02:56,000
for different properties.

57
00:02:56,000 --> 00:02:58,000
That was so easy to do.

58
00:02:58,000 --> 00:03:02,000
Now in the game manager, I'm going to choose color to something like, Well, let me choose.

59
00:03:03,000 --> 00:03:05,000
Yellowish and pay attention here.

60
00:03:05,000 --> 00:03:07,000
Alpha channel is zero.

61
00:03:07,000 --> 00:03:08,000
It's always like that by default.

62
00:03:08,000 --> 00:03:12,000
So we need to increase it to not make it transparent.

63
00:03:12,000 --> 00:03:14,000
Now we have Alpha channel full.

64
00:03:14,000 --> 00:03:17,000
We have purchased color on the platform.

65
00:03:17,000 --> 00:03:20,000
And let's go and see this first.

66
00:03:20,000 --> 00:03:21,000
Yeah.

67
00:03:21,000 --> 00:03:22,000
Now it's yellow.

68
00:03:22,000 --> 00:03:23,000
It's pretty.

69
00:03:23,000 --> 00:03:24,000
I like it a lot.

70
00:03:24,000 --> 00:03:27,000
But what if we don't want to change color of entire platform?

71
00:03:27,000 --> 00:03:32,000
What if we want to have kind of a header on the platform that we want to change?

72
00:03:32,000 --> 00:03:36,000
Well, I have a solution for that because I made the problem, so I have the solution.

73
00:03:37,000 --> 00:03:39,000
Let's go to level part our platform.

74
00:03:39,000 --> 00:03:46,000
We need to find our platform and I'm going to create another child here that will be Sprite Square.

75
00:03:48,000 --> 00:03:50,000
I'm going to call it as Heather.

76
00:03:52,000 --> 00:03:54,000
Going to choose certain layer.

77
00:03:54,000 --> 00:04:01,000
Platform one I'm going to do order layer one and I want to change color to default color.

78
00:04:01,000 --> 00:04:05,000
We have here reset position.

79
00:04:06,000 --> 00:04:10,000
Now we need to go to platform itself and get reference to that header.

80
00:04:10,000 --> 00:04:17,000
So serialize Field Private Sprite Renderer header S.r.

81
00:04:18,000 --> 00:04:21,000
And now we need to start function, start.

82
00:04:21,000 --> 00:04:25,000
And through the start function, we're going to change and control size of the header.

83
00:04:26,000 --> 00:04:32,000
What I mean by that, look at the moment we have a couple of issues with the header because scale of

84
00:04:32,000 --> 00:04:35,000
the child changes always according to the parent.

85
00:04:35,000 --> 00:04:41,000
So for example, if I would make this different color and I would make it slimmer just like that and

86
00:04:41,000 --> 00:04:44,000
I suppose this would be want, right?

87
00:04:44,000 --> 00:04:49,000
And if I would make another platform and I would change the size of this platform to something like

88
00:04:49,000 --> 00:04:50,000
this, look at the header.

89
00:04:51,000 --> 00:04:55,000
You see, it's wider, it's slimmer, it's not what we need.

90
00:04:55,000 --> 00:04:58,000
We want to have same size all the time.

91
00:04:58,000 --> 00:05:01,000
At least that's what I want and we have to do it through the code.

92
00:05:01,000 --> 00:05:09,000
Because now, even though scale is 0.5 here and 0.5 here, they obviously different because it is a

93
00:05:09,000 --> 00:05:12,000
scale according to the parent we have here, How we can do that.

94
00:05:12,000 --> 00:05:17,000
First, we can assign new parent and I'm going to assign level parts as a parent.

95
00:05:17,000 --> 00:05:23,000
So it still will be deleted together with the level part, but it won't have scale according to the

96
00:05:23,000 --> 00:05:24,000
platform.

97
00:05:24,000 --> 00:05:30,000
And second, I'm going to assign scale of the header according to the size of the platform.

98
00:05:30,000 --> 00:05:31,000
What I mean by that.

99
00:05:31,000 --> 00:05:33,000
So I'm going to create new blood firm.

100
00:05:34,000 --> 00:05:35,000
Like that.

101
00:05:35,000 --> 00:05:41,000
Then I'm going to take Heather and remove it from the platform and make a child of the level part like

102
00:05:41,000 --> 00:05:41,000
that.

103
00:05:41,000 --> 00:05:49,000
Now Heather is separated object, and now if I change skill to 0.1, it's going to be slim like that.

104
00:05:49,000 --> 00:05:50,000
All right.

105
00:05:50,000 --> 00:05:52,000
Now, if I take another platform.

106
00:05:53,000 --> 00:05:54,000
And I'll make it.

107
00:05:54,000 --> 00:05:55,000
Let's say.

108
00:05:56,000 --> 00:05:57,000
This much white.

109
00:05:57,000 --> 00:05:59,000
You see how Heather looks by default.

110
00:05:59,000 --> 00:06:06,000
But if I take it from here and make it child of the leveled part, not the platform, and then I'm going

111
00:06:06,000 --> 00:06:08,000
to change scale to point one again.

112
00:06:09,000 --> 00:06:12,000
You see how it looks now?

113
00:06:12,000 --> 00:06:17,000
Their only task here will be to put it on the top to make it look like this.

114
00:06:18,000 --> 00:06:20,000
And we can do all of that in the code.

115
00:06:20,000 --> 00:06:21,000
Let's go and do that.

116
00:06:23,000 --> 00:06:24,000
Let's go to the code of the platform.

117
00:06:25,000 --> 00:06:27,000
First, let's assign Heather here.

118
00:06:27,000 --> 00:06:28,000
Okay.

119
00:06:28,000 --> 00:06:30,000
Now it's assigned in the inspector.

120
00:06:30,000 --> 00:06:39,000
And over here, first, what we can do is Heather S.r, dot transform, Dot parent equals to transform

121
00:06:39,000 --> 00:06:39,000
parent.

122
00:06:39,000 --> 00:06:45,000
So we send it parent of the heather will be my parent, parent of this transform.

123
00:06:45,000 --> 00:06:48,000
And this transform is a platform, and his parent is a level part.

124
00:06:48,000 --> 00:06:49,000
I hope it's not confusing.

125
00:06:49,000 --> 00:06:52,000
We assign the parent just like I did with my mouse.

126
00:06:52,000 --> 00:07:01,000
Now we need to change the size and for that I can do Heather As our transform, local scale equals two.

127
00:07:01,000 --> 00:07:05,000
And now I'm going to take my size and let's do new vector two for the x.

128
00:07:05,000 --> 00:07:07,000
It should be same as a platform.

129
00:07:07,000 --> 00:07:08,000
So SSE are.

130
00:07:10,000 --> 00:07:15,000
Bounce size X and for the Y we want to set value.

131
00:07:15,000 --> 00:07:21,000
And if you remember, I did set scale to 0.1, so I'll just type here, point one.

132
00:07:23,000 --> 00:07:24,000
Oh, let's try point two.

133
00:07:24,000 --> 00:07:27,000
I want to see how it looks with the two some point two F.

134
00:07:28,000 --> 00:07:30,000
Now half job is done here.

135
00:07:30,000 --> 00:07:31,000
Let's go and check this one.

136
00:07:31,000 --> 00:07:37,000
And to make it easier to check for us, I'm going to first I'm going to change color back to default.

137
00:07:38,000 --> 00:07:45,000
I'm going to create another platform, place it on the right, but I'm going to make it slimmer, much

138
00:07:45,000 --> 00:07:48,000
slimmer than another one I'll place here.

139
00:07:49,000 --> 00:07:50,000
And I'm going to make it wider.

140
00:07:52,000 --> 00:07:54,000
Now let's go and see if it works.

141
00:07:54,000 --> 00:07:55,000
Now, wait.

142
00:07:55,000 --> 00:07:56,000
We need to change.

143
00:07:58,000 --> 00:07:59,000
And point as well.

144
00:08:00,000 --> 00:08:02,000
So it won't be overlaid.

145
00:08:05,000 --> 00:08:07,000
Especially with the below, even with the gizmos.

146
00:08:08,000 --> 00:08:09,000
Let's go and see.

147
00:08:09,000 --> 00:08:12,000
Oh, I forgot something important.

148
00:08:12,000 --> 00:08:12,000
Yeah.

149
00:08:12,000 --> 00:08:13,000
I'm sorry.

150
00:08:13,000 --> 00:08:14,000
We need to change.

151
00:08:14,000 --> 00:08:18,000
Actually, not as our color, but Heather as our trigger enter.

152
00:08:18,000 --> 00:08:20,000
And I hope you did notice that before me.

153
00:08:20,000 --> 00:08:23,000
So I'm going to come in this line just in case we need it.

154
00:08:23,000 --> 00:08:30,000
And over here in the top, Heather, as are color equals to game manager dot, instant dot, platform

155
00:08:30,000 --> 00:08:30,000
color.

156
00:08:31,000 --> 00:08:32,000
Okay.

157
00:08:44,000 --> 00:08:44,000
Check this out.

158
00:08:44,000 --> 00:08:45,000
It's slim.

159
00:08:46,000 --> 00:08:48,000
Same as the next one.

160
00:08:48,000 --> 00:08:50,000
Completely same size.

161
00:08:50,000 --> 00:08:51,000
Oh.

162
00:08:52,000 --> 00:08:53,000
I forgot to jump.

163
00:08:55,000 --> 00:09:03,000
Let me take my level generator and set distance to delete 200 so it won't be deleted earlier than we

164
00:09:03,000 --> 00:09:03,000
need.

165
00:09:08,000 --> 00:09:09,000
Cool.

166
00:09:09,000 --> 00:09:10,000
I like it.

167
00:09:10,000 --> 00:09:12,000
Now, you see the issue there, right?

168
00:09:12,000 --> 00:09:16,000
One of the header is below the top point and we're going to fix that now.

169
00:09:16,000 --> 00:09:18,000
How are we going to fix that?

170
00:09:18,000 --> 00:09:26,000
Let's go back to code of the platform and we're going to say, Heather, as our transform position equals

171
00:09:26,000 --> 00:09:28,000
to new vector two.

172
00:09:28,000 --> 00:09:30,000
Or actually we can use vector two here as well.

173
00:09:32,000 --> 00:09:35,000
And then we're going to take our x x of the platform.

174
00:09:35,000 --> 00:09:37,000
So transform position that x.

175
00:09:37,000 --> 00:09:47,000
And for the Y, we're going to do S.R Dot bound and bound is a box of the renderer dot max.

176
00:09:47,000 --> 00:09:50,000
And here you can see the maximal point of the box.

177
00:09:50,000 --> 00:09:52,000
And then we choose y.

178
00:09:52,000 --> 00:09:54,000
So maximum y of the box.

179
00:09:54,000 --> 00:10:01,000
And if you imagine a box there, this is the box and this is the y axis right up and down, and it takes

180
00:10:01,000 --> 00:10:03,000
the maximum point of the box over here.

181
00:10:03,000 --> 00:10:09,000
So it's going to be placed here at the top and we're going to take same transform position of the X.

182
00:10:09,000 --> 00:10:11,000
So it's going to be exactly the same.

183
00:10:11,000 --> 00:10:12,000
Let's go and see this.

184
00:10:14,000 --> 00:10:20,000
And just for experiment, I'm going to do I'm going to place this one higher, this one higher, and

185
00:10:20,000 --> 00:10:22,000
I'm going to make another one.

186
00:10:24,000 --> 00:10:26,000
Slimmer and smaller.

187
00:10:27,000 --> 00:10:28,000
They said higher.

188
00:10:30,000 --> 00:10:32,000
I'm going to take one point and move it to the right.

189
00:10:33,000 --> 00:10:34,000
Let's go.

190
00:10:35,000 --> 00:10:36,000
Now it's all same size.

191
00:10:37,000 --> 00:10:37,000
Very cool.

192
00:10:38,000 --> 00:10:39,000
And my boxes are kind of big.

193
00:10:39,000 --> 00:10:40,000
I could make it smaller.

194
00:10:44,000 --> 00:10:47,000
Now we can see actually, our player is standing.

195
00:10:48,000 --> 00:10:50,000
And bit in the middle of this parade.

196
00:10:50,000 --> 00:10:51,000
And I think it's okay.

197
00:10:51,000 --> 00:10:55,000
It looks like it has some kind of 3D dimension.

198
00:10:55,000 --> 00:10:57,000
Like it goes there deeper.

199
00:10:57,000 --> 00:11:04,000
But if we want to make it and place it exactly at the top, well, let's just go to code and it's our

200
00:11:04,000 --> 00:11:04,000
bond.

201
00:11:04,000 --> 00:11:05,000
Max, Why?

202
00:11:05,000 --> 00:11:09,000
And we're going to do here minus point one F.

203
00:11:09,000 --> 00:11:11,000
Actually, let me tell you.

204
00:11:11,000 --> 00:11:13,000
Where did they get this number?

205
00:11:13,000 --> 00:11:17,000
I just I found it before I was recorded, but I think it would be honest to show you.

206
00:11:17,000 --> 00:11:18,000
How did they get this number?

207
00:11:18,000 --> 00:11:19,000
0.1 F?

208
00:11:19,000 --> 00:11:20,000
Exactly.

209
00:11:20,000 --> 00:11:20,000
Why is that?

210
00:11:22,000 --> 00:11:24,000
So if I take my platform over here.

211
00:11:26,000 --> 00:11:32,000
And if I'll move it just above, just by a bit, you can see my y position is 0.666.

212
00:11:32,000 --> 00:11:33,000
If I move it.

213
00:11:35,000 --> 00:11:35,000
Yeah.

214
00:11:35,000 --> 00:11:36,000
If you place it.

215
00:11:36,000 --> 00:11:37,000
Exactly.

216
00:11:39,000 --> 00:11:42,000
Here, it would be 1.777.6.

217
00:11:42,000 --> 00:11:48,000
So basically 0.1 F and I'm just addressed by -0.1 F, and basically it's done.

218
00:11:48,000 --> 00:11:52,000
Now it's up to you to color header of the platform or entire platform.

219
00:11:52,000 --> 00:11:54,000
You can choose anything you like.

220
00:11:54,000 --> 00:11:55,000
You just need to adjust this code.

221
00:11:55,000 --> 00:11:56,000
But actually you know what?

222
00:11:56,000 --> 00:11:58,000
We could make it customizable.

223
00:11:58,000 --> 00:12:06,000
Let's go to game manager over here and just create boolean public bool that I'm going to name as color

224
00:12:07,000 --> 00:12:08,000
entire platform.

225
00:12:09,000 --> 00:12:09,000
Yeah.

226
00:12:10,000 --> 00:12:13,000
Now and trigger enter.

227
00:12:13,000 --> 00:12:14,000
We can check.

228
00:12:14,000 --> 00:12:22,000
I'm going to open curly brackets and say if game manager that instance says color entire platform.

229
00:12:23,000 --> 00:12:29,000
Then we would color hair and we could color the body as well.

230
00:12:30,000 --> 00:12:34,000
If it doesn't say color into our platform, we can just color else.

231
00:12:34,000 --> 00:12:35,000
Heather is our color.

232
00:12:37,000 --> 00:12:37,000
Just like that.

233
00:12:37,000 --> 00:12:38,000
Let's go and see this.

234
00:12:38,000 --> 00:12:40,000
I'm going to press enter over here.

235
00:12:40,000 --> 00:12:41,000
Let's go and see this.

236
00:12:41,000 --> 00:12:48,000
So I have an and game manager that says color entire platform and it's false and then colored only header.

237
00:12:50,000 --> 00:12:51,000
Now if I change it.

238
00:12:55,000 --> 00:12:58,000
Now I'm coloring the entire platform because boolean is true.

239
00:12:59,000 --> 00:13:03,000
And actually you could get another effect here, which is also a bit preachy.

240
00:13:04,000 --> 00:13:11,000
If you just comment out this line here, it will color entire platform but not header and it would give

241
00:13:11,000 --> 00:13:13,000
us a different effect.

242
00:13:15,000 --> 00:13:16,000
Let me check this balloon.

243
00:13:21,000 --> 00:13:22,000
Now you see this?

244
00:13:23,000 --> 00:13:27,000
The platform is coloured but not the header, which is also looks pretty.

245
00:13:28,000 --> 00:13:31,000
And by the way, this is colors of my country almost.

246
00:13:31,000 --> 00:13:32,000
I'm from Ukraine.

247
00:13:32,000 --> 00:13:33,000
Yellow and blue.

248
00:13:33,000 --> 00:13:33,000
Probably.

249
00:13:33,000 --> 00:13:34,000
You've seen it before.

250
00:13:34,000 --> 00:13:35,000
All right.

251
00:13:36,000 --> 00:13:37,000
We done for this video.

252
00:13:38,000 --> 00:13:40,000
It was quite long, even though we did something simple.

253
00:13:40,000 --> 00:13:43,000
I just got carried away by different options we can do in this game.

254
00:13:44,000 --> 00:13:45,000
See you in the next video.

255
00:13:45,000 --> 00:13:46,000
Bye.

