Hello guys.
Welcome to the video.
In this one I want to show you how to make the pose UI so you can pause the game while you're playing.
And also you can click escape and go to main menu.
Simple task here.
And we just need to make.
Let's make UI.
Uh, I guess we can do image now.
Let's not do image.
Let's do empty object pose.
Pose UI.
Okay.
On this post, we need to stretch it on the entire screen.
Now let's focus on this and we can make some sort of a button.
Button text Mesh Pro.
Uh, it would do.
Resume.
Uh, actually, let's set up the button first.
Let's do 250 by 100.
And this would say resume.
Let's make text white.
Let's do Minecraft font.
Okay, I think I like it.
Maybe bigger font.
Or G6.
Maybe a bigger button.
350 by 150.
Yeah, it looks good.
So you cannot miss it.
And let's change it to resume.
Button and we want to duplicate this.
Bring it down and change this to.
Menu button and this will have something like.
Main menu.
Yeah, we need to decrease font a little bit, but we can just do 68 over here or 58.
58.
64.
Looks good.
Okay, let's take resume and do 64 as well.
So it's the same.
Let me think.
I don't like how the like.
I don't like the height of the buttons.
So I'm going to try to do 100 here.
Yeah, it looks better.
Let me take the text.
Change the textbox size over here and over here.
Now we want to make UI image.
We want to stretch it on the entire UI and we want to make it.
Dark and transparent, and I guess we need to place it above the buttons.
So buttons dominate.
Nice.
Um, pose.
Dark screen.
Let's make it Unclickable.
We're going to click over here.
Raycast.
Target.
And that's probably it for the UI itself.
The only thing I want to change is to make buttons a little bit transparent here.
Like that.
Okay.
This is very good.
I like it.
Now we need to make functionality for this.
We can go to UI in game.
And I'm going to make a method.
Public void.
Pause button.
Now we need a boolean that defines if game is paused at the moment Privatebool is paused.
And then over here in a pause button.
We're going to do this if is paused.
Then it means we resuming the game when we pressing this button.
So we're going to do is post equals to false.
And we're going to do time dot time scale equals to one.
So time scale defines how like how fast game goes.
You know it's a time scale.
If you make it uh point five you're going to have a slow motion in the game.
But it does not work very well in the pixelated game.
Anyway, with this one, we're going to return normal time to the game, and we're going to say that
game is not paused anymore.
And over here we're going to do else.
So if it's not post then we're going to do is post.
It was to true and time to time scale equals to zero.
Now even this alone is going to work.
I just want to open up date and I'm going to do if input.
Get key down.
He called and I'm going to choose letter B for this.
But you can use any other letter.
And if I'm pressing P I'm going to call pause button.
But now this should be enough.
Let's go back to the game.
Let's disable this false UI for now.
And let's just try the pause system.
So I'm in the game.
I'm going to press P and game stopped.
Timer stopped.
Everything stopped.
Very cool.
If I'm pressing P again.
Game is resumed.
So it works.
Now we need to, um.
Enable this UI when we press in the button.
And also we need to set up these two buttons.
Right.
Let's go back.
Let's get reference.
Private game object pose UI.
And we need a method that would go to the main menu.
So.
Over here.
I'm going to do public void.
Go to main menu button.
And we know that main menu has index zero.
So I'm just going to do seed manager.
Below the scene of zero.
This should be enough.
Okay, let's save this.
Let's go back to unity.
On the resume button.
We need to add event drag UI in game, find UI in game, and just assign a pause button over here for
the main menu.
We need to add event drag UI in game and assign.
And go to main menu button.
All right, now let's go to play mode.
I'm going to click escape.
Oh, I forgot something.
I'm so sorry.
Yeah.
Uh, let's go to UI in game, and let's drag this pose UI over here.
So we have reference to the game object.
And then over here we're going to do.
Pause UI.
Set active false.
And over here we're going to do pause UI.
Set active true.
This is what I forgot.
Let's save this.
Let's go back.
And now supposed to work.
Going to press escape.
Oh, why?
I'm pressing escape.
It's a platter.
Yes.
So?
It's working.
Very good.
And you can click resume.
Works as well.
And you can go to main menu.
All right.
So this works.
Let's uh go to UI in game.
Let's do apply all.
Now we can go to another scene and test this scene level two I'm going to save it here we have post
UI.
Now it is disabled.
And in the next scene I can press the pause game as well.
Alrighty.
See you in the next video.