Hello, guys.
In this video, we're going to change color of the platforms and that will be our last features before
we make level parts.
I guess.
So what are we going to do here?
Basically something very simple we're going to use on trigger enter.
We're going to get access to component of the sprite renderer and on trigger enter.
We're going to change color.
So I guess you know what to do now and you can try to do it as a challenge.
All right.
Go and try to do that.
So when you step on the platform, you change the color of the platform.
You have a couple of seconds before I continue and show what to do.
One, two, three.
So what we do here, I'm going to take my level part and I did delete traps because I want to have an
easy test in here.
Let's take the platform.
I'm going to create empty object under the platform and I'm going to call it body.
Then I'm going to add component of Box Collider.
And now whenever I change size of the platform.
I changed scale of the platform to any size I want Collider of my body going to have same size.
So we have nothing to worry about when we change platform and now we can take a leader of the parent
over here and make it A's trigger.
All right.
It is done.
Now let's go and add component.
New script.
Platform.
Controller.
I guess now what I'm going to do here first is to get access to Sprite Renderer Serialize Field.
By what bright renderer S.r At this time I don't want to do it in the start.
I'll just do it in the inspector as well.
I do need an update.
And now on trigger enter to DD.
You're going to check if collision happens with the player.
So if collision dot get component of a player not equals to null, then we take S.R, dot color equals
two and we're going to assign new color.
And as of now we don't have any color shop or anything.
I'm just going to write color dot white just for testing.
Let's go there now.
I'm going to drag my Sprite renderer over here.
And going to go back.
I'll let me check my endpoint.
Well, it can be a bit further, so we have to jump sometimes.
Now, look, I step on the platform and I change colour of the platform.
Now, first question, What if you want to have different color, not white?
We're going to purchase colors from the shop that we're going to create later.
As of now, let's just create a variable in the game manager.
Mhm.
Public color.
Lot form color.
And in the platform controller instead of white.
We're going to do game manager.
That instance, that platform color.
See, that was I was talking about when I was saying we need a game manager that we can use as a hub
for different properties.
That was so easy to do.
Now in the game manager, I'm going to choose color to something like, Well, let me choose.
Yellowish and pay attention here.
Alpha channel is zero.
It's always like that by default.
So we need to increase it to not make it transparent.
Now we have Alpha channel full.
We have purchased color on the platform.
And let's go and see this first.
Yeah.
Now it's yellow.
It's pretty.
I like it a lot.
But what if we don't want to change color of entire platform?
What if we want to have kind of a header on the platform that we want to change?
Well, I have a solution for that because I made the problem, so I have the solution.
Let's go to level part our platform.
We need to find our platform and I'm going to create another child here that will be Sprite Square.
I'm going to call it as Heather.
Going to choose certain layer.
Platform one I'm going to do order layer one and I want to change color to default color.
We have here reset position.
Now we need to go to platform itself and get reference to that header.
So serialize Field Private Sprite Renderer header S.r.
And now we need to start function, start.
And through the start function, we're going to change and control size of the header.
What I mean by that, look at the moment we have a couple of issues with the header because scale of
the child changes always according to the parent.
So for example, if I would make this different color and I would make it slimmer just like that and
I suppose this would be want, right?
And if I would make another platform and I would change the size of this platform to something like
this, look at the header.
You see, it's wider, it's slimmer, it's not what we need.
We want to have same size all the time.
At least that's what I want and we have to do it through the code.
Because now, even though scale is 0.5 here and 0.5 here, they obviously different because it is a
scale according to the parent we have here, How we can do that.
First, we can assign new parent and I'm going to assign level parts as a parent.
So it still will be deleted together with the level part, but it won't have scale according to the
platform.
And second, I'm going to assign scale of the header according to the size of the platform.
What I mean by that.
So I'm going to create new blood firm.
Like that.
Then I'm going to take Heather and remove it from the platform and make a child of the level part like
that.
Now Heather is separated object, and now if I change skill to 0.1, it's going to be slim like that.
All right.
Now, if I take another platform.
And I'll make it.
Let's say.
This much white.
You see how Heather looks by default.
But if I take it from here and make it child of the leveled part, not the platform, and then I'm going
to change scale to point one again.
You see how it looks now?
Their only task here will be to put it on the top to make it look like this.
And we can do all of that in the code.
Let's go and do that.
Let's go to the code of the platform.
First, let's assign Heather here.
Okay.
Now it's assigned in the inspector.
And over here, first, what we can do is Heather S.r, dot transform, Dot parent equals to transform
parent.
So we send it parent of the heather will be my parent, parent of this transform.
And this transform is a platform, and his parent is a level part.
I hope it's not confusing.
We assign the parent just like I did with my mouse.
Now we need to change the size and for that I can do Heather As our transform, local scale equals two.
And now I'm going to take my size and let's do new vector two for the x.
It should be same as a platform.
So SSE are.
Bounce size X and for the Y we want to set value.
And if you remember, I did set scale to 0.1, so I'll just type here, point one.
Oh, let's try point two.
I want to see how it looks with the two some point two F.
Now half job is done here.
Let's go and check this one.
And to make it easier to check for us, I'm going to first I'm going to change color back to default.
I'm going to create another platform, place it on the right, but I'm going to make it slimmer, much
slimmer than another one I'll place here.
And I'm going to make it wider.
Now let's go and see if it works.
Now, wait.
We need to change.
And point as well.
So it won't be overlaid.
Especially with the below, even with the gizmos.
Let's go and see.
Oh, I forgot something important.
Yeah.
I'm sorry.
We need to change.
Actually, not as our color, but Heather as our trigger enter.
And I hope you did notice that before me.
So I'm going to come in this line just in case we need it.
And over here in the top, Heather, as are color equals to game manager dot, instant dot, platform
color.
Okay.
Check this out.
It's slim.
Same as the next one.
Completely same size.
Oh.
I forgot to jump.
Let me take my level generator and set distance to delete 200 so it won't be deleted earlier than we
need.
Cool.
I like it.
Now, you see the issue there, right?
One of the header is below the top point and we're going to fix that now.
How are we going to fix that?
Let's go back to code of the platform and we're going to say, Heather, as our transform position equals
to new vector two.
Or actually we can use vector two here as well.
And then we're going to take our x x of the platform.
So transform position that x.
And for the Y, we're going to do S.R Dot bound and bound is a box of the renderer dot max.
And here you can see the maximal point of the box.
And then we choose y.
So maximum y of the box.
And if you imagine a box there, this is the box and this is the y axis right up and down, and it takes
the maximum point of the box over here.
So it's going to be placed here at the top and we're going to take same transform position of the X.
So it's going to be exactly the same.
Let's go and see this.
And just for experiment, I'm going to do I'm going to place this one higher, this one higher, and
I'm going to make another one.
Slimmer and smaller.
They said higher.
I'm going to take one point and move it to the right.
Let's go.
Now it's all same size.
Very cool.
And my boxes are kind of big.
I could make it smaller.
Now we can see actually, our player is standing.
And bit in the middle of this parade.
And I think it's okay.
It looks like it has some kind of 3D dimension.
Like it goes there deeper.
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
bond.
Max, Why?
And we're going to do here minus point one F.
Actually, let me tell you.
Where did they get this number?
I just I found it before I was recorded, but I think it would be honest to show you.
How did they get this number?
0.1 F?
Exactly.
Why is that?
So if I take my platform over here.
And if I'll move it just above, just by a bit, you can see my y position is 0.666.
If I move it.
Yeah.
If you place it.
Exactly.
Here, it would be 1.777.6.
So basically 0.1 F and I'm just addressed by -0.1 F, and basically it's done.
Now it's up to you to color header of the platform or entire platform.
You can choose anything you like.
You just need to adjust this code.
But actually you know what?
We could make it customizable.
Let's go to game manager over here and just create boolean public bool that I'm going to name as color
entire platform.
Yeah.
Now and trigger enter.
We can check.
I'm going to open curly brackets and say if game manager that instance says color entire platform.
Then we would color hair and we could color the body as well.
If it doesn't say color into our platform, we can just color else.
Heather is our color.
Just like that.
Let's go and see this.
I'm going to press enter over here.
Let's go and see this.
So I have an and game manager that says color entire platform and it's false and then colored only header.
Now if I change it.
Now I'm coloring the entire platform because boolean is true.
And actually you could get another effect here, which is also a bit preachy.
If you just comment out this line here, it will color entire platform but not header and it would give
us a different effect.
Let me check this balloon.
Now you see this?
The platform is coloured but not the header, which is also looks pretty.
And by the way, this is colors of my country almost.
I'm from Ukraine.
Yellow and blue.
Probably.
You've seen it before.
All right.
We done for this video.
It was quite long, even though we did something simple.
I just got carried away by different options we can do in this game.
See you in the next video.
Bye.