Hello, guys.
In this video, I want to make another part of the shop work.
And I mean selling colors to the player, right?
I mean, colors of the player.
And as I said before, it's the best practice to reuse the code that you already have and not to create
same one because another set of buttons basically going to use the same functionality entirely, the
same.
So what we can do here is to just pass another value that says, is it a platform or is it a player
color?
And then we're going to do our actions according to that.
How are we going to do?
We can create an enum.
Enum allows you to define basically a type of something look, public enum, color type.
And inside I'm going to do first one is player player color, another one, platform color.
That's it.
We're going to keep it like this.
And now I can request this type over here, color type, color type.
We need to pass this value as well.
So let's go here and type color, type dot, platform color.
All right.
We have this now.
It's all the same.
But now we know that this function is exactly for platform color.
Next, we can setup buttons for player color.
For that, let's go above and create new bunch of variables.
Serialize field, private game object player color button then serialize field, private transform player,
color parent.
And then we need display serialize field private image player display.
Good enough we can make some headers so it's clear and easy and they're not firm colors.
And there.
Layer colors.
Then let's take this one and drag it here.
So it's all together in one section and over here.
Serialize field.
Prime color to sell.
Layer colors.
Okay, now it's all done here.
We're going to set up this later in the inspector.
Let's just create another for loop, basically the same as we did in the last video.
Just going to change something.
You're going to take this player of colors and paste it in here.
And here.
And in here.
Then we need to change here.
The button player color button.
And.
Oh, sorry.
Layer color.
Parent.
All right.
This can stay the same because we basically get an access to the same button as that one.
And add listener.
We only need to change color type, which is now player color.
Good.
Now we create in two sets of buttons, and the only functionality left is to decide which color we purchasing
according to the color type we use in in the if statement enough money, we're going to make another
if statement that says if color type equals equals to color type of the platform, then we're going
to do this two lines of code, same as we did before.
Nothing much changes here and we need another ls if I make an ls if because there can be more color
types, maybe you want to do something else like change color of the crops.
For example, if color type is equal to color type.
Dot player color.
Then game manager.
That instance dot player color equals to color and we need display.
We already have it.
So player display that color equals to color.
After all of that, after we decide which color we change in, I want to do debug line of successful
purchase, but I don't want to do it in the console because player doesn't have console when he plays
the game.
So we need to do it in a different way.
Luckily for us, if you remember we said text at the top of the shop, click to buy over here and we
can change this for some time.
So I want to create a core routine here.
I enumerator with the name notify.
We're going to pass a text.
We want to send string, text and maybe a delay.
So load seconds.
Then inside we're going to take that text, change it, wait for a couple of seconds, and then change
it back.
But we need access to that text.
Maybe somewhere above zero lies filled private text text match pro.
90 by text.
On to create a space here.
So it's easier to read.
Okay, then let's go back here and we say this 95 text.
That text equals to text we pass here.
Then we do yield.
Yield return.
You wait for seconds inside, we pass seconds to wait, and then we do 95 text 95 Text and text equals
to what was that click to buy.
Yeah.
Now let's go over here and start this core routine.
Start core routine 95 going to pass parameters, the text we want and the delay.
So I want to say purchase successful.
Let me copy it from here.
Purchase successful.
I can delete it from here now.
And I'm going to do it for I don't know.
One second.
This is good.
Now, what happens if there is not enough money?
Very simple.
We just do ls.
You do, you start quarantine that says.
Not enough money.
We can delete this line from here.
Do we need to change something else in the shop?
Yes, we do.
But first, let's go and see how this works.
I'm going to take my shock UI.
I'm going to close platform colors and I need to set up player colors.
Let me click this.
Lock it.
First we drag the button, so project prefab player button, then the parent.
Their parent then display image.
Player.
Then we need to set up colours.
We have.
Okay, I've got my colors.
Now let's rock.
Notify text.
Or is it in for text over here?
I'm going to change the name as well, just in case not to fi modify text.
OC.
We have it here and we can try this.
I have only 100 coins, but I think that should be enough.
Purchase successful.
Let me change the color of the player.
Not enough money.
Okay.
How about this one?
Boom.
Color change in the display.
But maybe you notice that actual color of the player is not changed at all.
So we need to fix that.
And also, we need to update the amount of money over here in the info bar.
It's going to be a pretty easy task.
We could do it in a couple of different ways.
What I want to do here is to delete player color from here, from the game manager.
Before I start, we can create a function here, but actually it's not really needed.
Let's go to UI shop and instead of this line we're going to do game manager dot instance, dot player
and get component of sprite renderer.
Then we're going to do dot color equals to color.
So we actually going to change the color.
And if you want to save the color, you can do game manager dot instance, dot save color and you need
to pass color dot.
Are color dot g colored dot b.
Yeah, this will do.
Also, we need to update the info bar, as I said, so let's go above and create another serialized
field.
Private text message, pro gooey coins.
Text.
We can go.
We can go over here.
Get this line of code and just go to the start and say that code and text.
Don't text equals to get into of the coins and we only need to do two string in the format and let's
copy this line of code and update this info not only on the start, but when our amount of money was
changed and this is happening over here so we can do it here, we're going to update the info every
time we purchase something.
That's basically it.
Yeah, I think so.
Let's go and modify a bit.
Let's go and make sure all of that is working.
I'm going to select my cannabis.
Shop UI.
Find the info bar.
There is a coin text over here and just going to drag it over here.
This is done, and I think we are ready.
I think that's it.
I only have 24 coins.
Wait a second.
Okay.
95 coins.
Let's go.
I'll purchase this color.
That is done.
I'll try this one.
Oh, not enough money.
Hmm.
Okay, let's try to purchase hero color.
We did it.
And it's all fine.
Now, the last one here, just in case you want to play this game on the PC, not the mobile.
We want to change the scroll speed over here, because when I try to do that with my wheel, it's really,
really hard to do.
Luckily, that is very easy.
Fix We need to choose player color, view, find scroll sensitivity and set it to something higher.
And let's do it out of the play mode.
These two scroll sensitivity 50.
And it's okay now.
Very good.
Now, regarding the color, what color should you sell?
You can make a random color or you can choose a bunch of colors, but sell only three at a time.
So every time you update the shop, it's going to be three out of ten or three out of 100.
For example, just make sure your colors are not too dark and not are the same as the background because
it's going to be difficult to see the player.
Yeah.
Let's go to the next video now.