Hello guys.
Welcome to the video.
In this one I want to show you how to update level buttons so they have a relevant information about
levels.
As example.
Let me just quickly explain.
So at the moment we have just level one, level two level three.
And what I want to do here is to display level name.
Then I want to show the best time on the level, like how many seconds it took you to complete the level.
And then over here I want to show you how many total fruits there are on the level, and also how many
fruits you collected from this level so player can see how many fruits he missed, and then he can just
go there again and collect all of the fruits.
Okay, also, if we did not unlock the level, if he did not play this level before, then we're going
to show zero out of question mark.
So we don't know how many fruits on the level there.
All right.
That's what we're going to do.
Uh, let's go to the skin selection UI.
I mean, level selection UI.
I'm going to take prefab UI level button, and I'm going to work on this button.
And then I'm going to just overwrite the prefab.
Okay.
So first I want to change the color.
Let's go to the button component.
Normal color will be something like dark blue.
I guess.
Yeah, something like this.
And then highlighted color will be light blue.
Is it blue?
I'm not sure.
Guys, I'm color blind.
Okay.
Now, when you put in your mouse over the button, it's going to look like this.
I think it's pretty.
Maybe put more work on the colors.
Yes.
Like that.
Now I'm going to take the text and let me change font to the Minecraft SDF.
Let's make it white.
And let's make the text box itself slimmer.
Like this.
I'm going to just maybe move it down a little bit.
And let's say this says level one.
Now let's change the name to level number.
Next and we want to duplicate this.
Let's move it below.
Let's change font size to 18.
And this one will be best time.
Let's say 99 seconds.
We've got.
Okay.
And I think we can do alignment to the left and just move it a little bit to the right.
Let me just attach it to the left side over here, and I'm going to move it to the right like that.
Yeah.
This should be good.
Now let's change this to best time text.
And also we want to duplicate it.
Actually I just want to move it a little bit here.
Down.
Okay.
Now I'm going to duplicate it.
This one going to be route text.
Now let's move it down and let's say this one will be fruits.
Um, zero out of five like that.
Now for the text over here.
I mean, for the fruits.
I want to add an icon.
So I'm going to go ahead and make UI image.
Let's name it as a fruit icon.
Then we're going to open image.
Go to graphics, find an apple and let's put Apple over here.
Nice.
Now I think the size should be smaller.
I'm going to try 60 by 60.
That looks good to me.
Let's just attach it to the center and move it to the right a little bit.
Yeah, like that should be good.
And now we're gonna.
Go to the script.
Make a variable for those two texts.
So I'm going to do serialize field private text mesh Pro.
Guy.
Uh, timer.
Best time text.
And we're going to neutralize field private text, mesh progue routes text.
All right.
Now we need to, uh, have information saved so we can pull this information, load it and give it to
the button.
As of now, we don't have this information, so I'm just going to go back to unity.
I'm going to assign text over here and throw text over here.
Then I want to do apply overrides and I'll disable this button.
Now let's go ahead to the Visual Studio.
And we need to save this information.
We need to know it.
So on the game manager.
Uh.
Somewhere here.
I'm going to make a method.
Private void.
Save best time.
And we're going to just do something simple here.
Playerprefs.
Set.
Float.
Level.
Plus level.
Plus current level index plus best time.
And we're going to give it value of a level timer just like that.
Now let's call it here.
Save best time and this will save the time.
So we don't need to check it, I know it.
Uh, we're just going to use it later on.
Let's make another method.
Private void save.
Routes info.
And before we do anything here, let's go to the collect fruit info over here.
And we want to save total amount of fruits on the level.
So we're going to do player pref.
Set int uh.
Level.
Sorry.
Level plus uh current level index plus total fruits and value will be total fruits.
So this will save it.
And we can use it on the button later on.
Now we're going to go down back to this method.
And over here we're going to do player.
Ref set.
End of level.
Plus, uh, current level index plus routes collected.
Now, this will save information about how many fruits we collected on the level.
And I kind of like it.
Uh, fruit collected.
But we need to do something here.
Imagine you collected four fruits on the level.
You save the info, then you run in the same level again.
And you did not collect four fruits.
You collected three.
And if you do not do anything in this method, then information will be overwritten and you'll have
three instead of four.
That's not what I want.
So we're going to do this.
We're going to make int.
Roads connected before equals to playerprefs.
Get int off.
And we're going to take this name over here and paste it in here like that.
And then we're going to check if fruits collected before is less than fruits collected.
Then we're going to set this integer over here.
So just like that we're getting the info from the previous session or from previous save.
And if it's less than we collect it now then we override it and we save information again.
Very cool.
Now for the total fruits collected, because we want to have some sort of a bank which we can use as
a currency to buy skins in the menu.
I'm going to do int total fruits in bank.
Why not playerprefs get int of?
Total fruits collected or actually I when I have a different name for this.
So it's at least a little bit dis dis dis.
I mean it's a little bit different from another one from this one.
So I couldn't say distinguished.
And now I did it.
Yes.
Okay.
So I'm going to do total fruits amount.
And here we're just getting the value.
And then we're going to do Playerprefs set int of total fruits amount.
Just so I won't make any mistakes.
I'm going to copy it from here and paste it in here.
And then I'm going to do total fruits in bank plus fruits collected in this way.
Whenever we save the level info, we're going to add fruits that we collected to the total bank we have.
And we can use it later on.
And I think that's all that we need.
Let me think about it.
We save the fruits collected on the level so we can display it on a button.
We did save total amount of fruits on the level, and we did save fruits that we collected.
So we can use them later on.
So this should be good.
Let's go here and call save route info.
This is nice.
And now we need to go to UI level button.
And over here we need to give info to these two texts over here.
So first of all, let's make a private string because I just want to return text timer info text.
And over here we're going to need the value of a timer we saved.
I'm going to go to Game Manager.
I'm going to copy this and I'm going to go to level button, paste the scene and we're going to do float.
Timer value equals to playerprefs.
Get float.
With a level index, and we don't have a default value here yet, but I want to give it a value of 99.
So if we don't have any best time, we're just going to put 99 there.
Let player know that this level was not completed yet.
Now we're going to return.
Best time columns, space plus timer value two string.
And we want to format it the same way as before zero zero.
And that's it.
Now on a setup button we're going to do best timer text dot text equals to timer info text.
Cool.
Now we need to do the same for the fruits we have.
It's going to be a little bit more complicated, but actually very simple.
Overall.
Let's make a private string.
Routes.
Info.
Text.
And over here.
We need to go to game manager.
First of all, I want to copy this.
Let me copy this.
I mean this line of code.
Over here.
We're going to do int total fruits on level equals to.
This and we're going to use level index.
And we don't want to have any default value.
Actually, we want to have a default value of a zero because I want to use it later on.
I'm going to show you how to.
And over here it's supposed to be get int.
And no parentheses over here.
Okay.
Maybe let's rename it to Total Fruits.
It's a bit better.
Now look, this will return us info if we did save a new value before.
But if we did not save anything, it's going to show us zero.
But I don't want to show zero.
I want to show question mark.
I want it to be intriguing.
So I'm going to make a local variable of a string, total fruits text.
And it will be decided by the quick if statement.
Over here we're going to do this equals two.
And then we're going to ask total fruits is equals to zero.
If yes, then total fruits text will be equal to question mark.
If no, then it's going to be equals to total fruits two string.
Very nice.
So this is decided.
Now we need info about fruits collected on the level.
I'm going to go to Game manager.
And over here we have this.
Fruits collected.
So I'm going to I can just take this one over here.
Let's take it.
Go back.
Paste it in.
And over here we're going to do int fruits collected equals to this.
And instead of current level index it will be level index.
And then this one going to return me.
Let's do return.
Return.
Um.
Rhodes columns, plus.
Jackfruits collected.
Plus SpaceX slash SpaceX.
Plus total fruits.
Text.
And I forgot semicolons over here.
Cool.
Super cool.
Now let's go to the setup button and do fruits text.
The text equals to fruits info text.
On this supposed to be good?
Actually, I did check it twice because I was recording this video and I forgot to press record button,
which sometimes happens to everyone.
I hope.
Now I'm going to go to.
Yeah.
And also I just did it once to make a prototype and see how it works.
But let's check it.
Let's do clear all playerprefs.
Going to go to play mode.
So by default it shows me 99 zero out of question mark going to jump on the level.
Can I collect some?
I'm going to go to the next one, complete the second one, but I'm not going to complete the third
one.
Because it has no fruits anyway.
Let's go out of a play mode.
Let's go to play mode again.
And over here we have new level unlocked which has 99 zero to the question mark here.
Best time was zero for fruits three out of six here.
It's a bit different.
Uh, four out of five.
And best time is four.
What to do?
Let me just double check.
It's not a bug.
I'm going to just wait for more time here.
It's going to be best time.
Oh, this is good.
I'm checking this because now I'm going to overwrite the info and it's not going to be the best time.
It's just going to be the last time I.
It took me.
Yeah.
Seven seconds.
Oh my God.
Okay, let's fix it.
Let's go to game manager.
Uh, over here on the save.
Best time.
We need to do load.
Last time equals to playerprefs get float.
And I'm a bit lazy.
I'm going to just copy it from here.
Paste it in here.
And default one can be 99.
And then I'm going to do this.
If level timer is less than last time, then we're going to save this.
Right.
They should be better.
Let me save the script.
Now we know that on a second level, it took me seven seconds.
And now I'm going to try to run this as fast as possible.
Seven.
Let's go.
And it was, uh, four seconds when I entered the finish line.
Let me see it now.
And it has for now.
Let me just double check.
I'm going to take longer.
And if I'm not wrong, it's not supposed to save any time there.
All right.
Zero for fruits, six out of six.
I love it, man.
This is so good.
Now this is it.
Let's save the project and let's go to the next video.