Hello, guys.
In this video, I want to take care of the last element of the canvas, and that is end game UI.
So what we need to do here is to switch on end game UI when player dies instead of restarting game instantly.
So we're going to switch it on.
We're going to update values inside and at the same point we switch in on this UI, we save in the info
and then player just need to restart the button, but all of the info will be saved by that moment just
in case.
If he, for example, switched off the application before he clicked, go to main menu for example.
Right.
This what we're going to do.
First, let's just modify and screen by a bit.
I want to take this score with below just like this, and then I want to take coins, move it above.
I want to reduce font size to 60.
And I want to duplicate this text of the coins, move it above, change it to the instance.
And this is a.
Distance here.
So it's going to be like this.
Very good.
Let's make all of the fonts bold.
I think it's going to look better.
And now we need to add the script here.
New script, UI and game.
Yeah.
We're going to get access to three types of we're going to get access to that text we have.
So it's going to be serialized field, private text, match pro we distance, then we need coins, coins
and we need score.
All right.
We have distance and the coins in the game manager at the moment, but score is not available because
score is a temp value.
But what we can do is to delete, float from here and create score public value over here.
Public float score.
Now it's going to be accessible from anywhere.
We can go back to end Game UI and in the start we can get access to game manager and I want to make
it a bit easier to write.
So I'll do this.
Game manager.
Manager equals to game manager instance and now distance not text equals to manager, distance to string
with the format and key.
I'm going to copy this to string so it's easier for me then coins text manager or you see in the sense
helps me.
Another one.
Score text to string.
Yeah, that's good.
We don't need update.
And what I also want to do here is to set timescale to zero time.
The time scale equals to zero.
If you remember, we set timescale to one by default in the UI, and I want to take this line of code
from here and transfer it to game manager that has more logic in it.
Let's put it here.
Good enough.
And the next thing we need to do, we need to make a function that will switch on end game UI.
And at the same time we'll save information about coins we collected and so on.
So let's go to game manager.
And create public void.
Game ended.
Inside.
We're going to do save info and if we have it here, we can remove it from restart level now.
After we save that info, we need to open in-game UI and we don't have access to UI yet, but we can
get it public UI main.
Then I call it just UI.
Then I want to go to UI Main create a function that will open this and game UI for me.
So public void open end game UI.
Now we need that end game UI.
So let's go here and create serialize field, private game, object and game.
And I want to put a space here.
Cool.
Now, here we're going to do switch menu to end game.
This is good in the endgame UI.
This is good.
Let's check on game UI.
This is okay.
Now let's go to game manager.
After we save that info, we go UI, open and game UI.
Cool.
Now what we need to do next.
We need to call this function first.
Let's call it from trigger dead zone over here Instead of restart level, we're going to call.
What was that game ended.
Let's copy this line.
Go to player.
And instead of free start level again, we're going to do this.
Now, we don't need a delay here.
And what I want to do is to change the time scale to something like point six or so, to make effect
of the slow motion.
When you get in hit, Let's do this time.
The time scale equals 2.6 F.
I'm going to drag it score wins distance, then switch it off.
Switch on main menu.
Let's go.
Boom.
I forgot something.
And that is a sign.
Canvas to game manager.
Yeah.
UI over here.
Tom.
What again?
Oh.
I'm sorry.
Yeah.
We need to sign in the game as well.
And the game.
Okay, Now it's going to work.
I hope.
Oh, no, it won't.
There is something else to update.
The text of the final score.
And let's go and fix that.
In the endgame UI.
You're going to type here.
Distance.
And plus then.
Plus again am.
And we're here.
We're going to type.
Points.
Plus.
And this one is.
Score.
Plus.
That is good.
Okay, This is good.
Now let's assign the button.
Main menu.
Let's drag the canvas.
UI restart game button.
All right.
It's working.
Now, let me hit the truck.
And if I hit the trap.
It's working perfect.
All right.
I'll see you in the next video.
Oh.
That this is empty because I had zero coins.
Okay, let's modify just by bit, just in case this happens with somebody else.
So what I want to do, I want to make sure one of these numbers has some value.
And if there is no value, we're not going to type anything at all.
This is what it looks like if manager.
Manager that distance less or equals to null then return if manager dot coins equals less or equals
to null, then return.
And we don't need to type anything about score because score cannot be zero unless one of those two
is zero.
Yeah.
Lets just select distance remove text.
Same for coins and fourscore.
Now, if I'll die with zero coins.
This field is going to be empty.
Good.
Let's go to next video now.