Welcome back.
In this video, we are going to add the high score.
And as you can see here, we already have this best zero, which is the best score.
And what we'll do is we'll add the functionality so that it actually does something.
So let's go to our game manager in order to do that.
And in there we need to create a new variable.
And I'm going to call that public text, high score text, because we need to somehow access the high
score text and we do that this way.
Next, when in the wake method, I'm going to assign the text of that high score.
And in order to do that, I do the following.
I get the high score, which is actually a new variable.
So let's do that as well, public and high score.
So we need a high score variable, which is just the value as a number and we need the text, which
is the representation on the guy.
And in order to change the high score or assign the high score from the start.
So whenever we start the game, we set the high score to player press, dot, get int and then here
we just enter the key high score.
So the player press is a class which allows us to save very little information so just a very which
stores so the player press is a class which stores and accesses player preferences between game sessions
that's used for for example the preferences that the player has set up.
So let's say the volume or the resolution that he's using or the high score or stuff like that.
And that's perfect for what we want to use.
So it's great to score store information such as integers or strings.
It's not really good for anything else.
So it's just if you look at it, get int, float and string.
So these are the types that you can store within player press and that's how you can get an integer
and the integer that is saved or stored at the key of high score.
So you could enter whatever you want here.
It will check if for that key that you have entered here is anything that is an integer and that can
be fetched or obtained.
Whatever that will be will be initialized or assigned to our high score variable, which is our integer.
And now we can go ahead and set the high score text to the high score.
And the best version here is best empty space and plus high score.
Now this is how we can obtain this score.
But now you might wonder, how do we save the score?
Well, we do that in increased score with a simple if statement here.
We check if our score is higher than the high score.
And if that's the case, then we store this course.
So we use player press to set an integer before we gotten the integer with get integer.
Now we set the integer with set int and in here we just say which key we want to use and we use this
key high score and then the value that we want to store.
And that's going to be our score.
And at the same time we want to apply that to our high score text as well.
So we update our high score text with the latest score.
And of course, that's not a string, so we need to cast it to a string.
All right.
So this is how you save it and that's how you obtain it.
So you need to use the same key that's important.
Otherwise it will not find anything.
And then high score will be empty.
Now let's save that script and let's go back to Unity and run our game, get some points and increase
our score.
Actually, I screwed up there.
Once again, let's get some points.
As you can see, our best is not changed yet and that has to do with us not accessing it.
And let's stop the game.
We can see score is 78, so now the best is still zero.
And that's because we're not assigning it.
So our game manager doesn't have a score or a high score text yet.
So let's get the high score text from our canvas in here and let's drag it in.
So now let's start again.
You might see direct or we should see Directive 78.
There it is.
So 78 is our high score and it's directly assigned to it.
Great.
So what I want to have is that the score goes back to best zero and the score here goes also to zero
whenever we are on the game over screen and I want to see the best score or the high score on our game
over panel as well.
So I'm going to duplicate this game over label score text and I'm going to drag it up and I'm going
to call it game over label, high score text.
So what that should do is it should show the high score and that should be at -120 maybe.
Yeah, that should be fine at -120 and it should not show score, but high score.
So high score is zero.
Now we need, of course, to edit our game manager a little bit in order to make it available as well.
So in here we only had our game over panel score text.
Now we need to game over.
Panel High score text.
And in on Bob hit.
What I want to do is I want to set the game over panel high score to the best score.
So game over, panel.
High score text.
Text is equal to best colon plus high score to string.
So now we do that on bottom hit.
So whenever we hit the bump, we set the score text and the high score text.
And then while we do the high score getting in our wake method, a better version is of course to or
a better way to do that is to have an additional method for that.
So public void get or actually public.
Void, get high score and in here we are simply going to do just that.
So we're going to get the high score and now we can call it in here, get high score.
And actually we don't need to make it public.
It can be private because why would we call it from another class?
If we should want to call it from another class, we could, of course, change it back to to public.
But as we only will use it in our awake method, we can use it or in this class better serve than the
game manager.
We will keep it private now while we are in the game manager, let's clean up the score text, text
as well, because so far we only set it to zero and a better version would be to go ahead and call it
score to string.
So whatever the score is, in this case, it's zero.
We can also just call it coach scoring here and the game over.
Panel Text Score zero is not required anymore because the only way we will do that anyways is when we
hit the BOM, so we won't need to set that back to zero as it will only show the assigned score anyways.
All right.
So now before we test that, let's check out our game manager.
It needs some game over panel, high score.
So game over label high score.
And I call that label high score.
It should be panel high score maybe.
Let's rename those panel score and that one panel high score.
So now let's test that.
Let's hit it and we see best 78, let's restart and we see our score is displayed correctly and we can
kill bombs and boom, I hit the bomb and I it shows the score.
It shows the best.
And I can restart the game.
Great.
So in the next video, we are going to have a look at creating our own fruits in blender and then afterwards
we will extend the game a little bit.