Hello, guys.
In this video, we're going to set up pause button.
Going to be pretty simple task.
I want to go to the canvas.
you-I mean, first we need to create a bullion private ball game post.
Now let's create a function public void.
Bull's game.
And we're going to do simple check if game post.
Then time the time scale equals to one.
Regular time scale is one.
Then we're going to say gain post is false.
Then we're going to do ls and ls means.
If game is not paused, then we're going to pause it.
How are we going to do it?
We're going to set time the time scale to zero, which allows us to stop all the time in the game and
then game post equals true.
So we have boolean prepared for the next check.
In this if statement.
All right.
This is pretty simple and understandable.
I'm going to find this post button hit plus drag canvas and then do UI pause game.
Stopped.
Resume.
Stopped resume.
Cool.
Now you can notice something.
After you clicked UI with your mouse, you can click the button again with your space key.
So it's just activated by my space now, which is okay because it won't be there when you build the
game, but it's kind of annoying when you're testing.
So what we can do here is to go to this navigation and just choose none.
And it's going to be fine and it won't be there.
You can see I can jump now and there is no game post at the moment.
Cool.
Now next step would be to switch UI.
It's going to be pretty simple with the setup we already have.
Let's hit.
Plus over here.
Drag the canvas.
Choose UI main switch menu to pause ui.
And then in the post UI, we're going to open it, find a pause button and add almost the same functionality.
Canvas.
First one will do post game to unpause it and second one will do UI.
Main switch menu two.
And we're going to switch to in-game UI.
Pretty cool.
Let's go and see this game post.
I can click again and post.
And regarding this button, well, let's do it right now.
It's not that big of a deal.
Let's find this main menu.
Drag, canvas.
Oh, wait a second.
Plus, drag the canvas and choose UI main.
We need a restart game.
Do we have it?
It's in the game Manager.
Okay.
So I want to move this function to UI as well.
Let's find this UI main.
Let's rename this buttons just a bit.
Let's press control r r to rename it all and it's going to be start game button.
This one as well.
Pause.
Game button.
Then let's create one more here.
Public void.
Restart game button and it's going to do.
Return game manager, for instance.
Restart level.
Now let's go and double check.
We have all of those functions in the UI.
Suppose the main menu function UI menu restart game button.
Now this one is missing.
Now we need to do UI.
Post game button.
Same here is going to miss here ui pause game button.
And.
Top to start as well.
Top to start meetings.
So we need to update.
Where is it?
Start game button.
Okay.
So we have.
This.
Bows and bows.
Bows.
Main menu.
Now we can see we went to a new scene and game was restarted, but UI wasn't.
So what we need to do here is something very simple.
We just need to go to UI main and create start function.
There's going to say switch menu, too.
And now we need the reference to main menu.
So let's do this.
Serialize field Private game object.
Main menu.
Then.
Here.
Main menu.
As we go to Unity and update the info main menu.
And also at the start, we need to set timescale to one again because we set them scale to zero when
we're in a post mode and when we go from the pause mode to main menu.
We're not setting timescale back to one, so we need to do it in the start time.
Dot timescale equals to one later.
We can do it in the game manager, but for now we can do it here.
Let's go to play mode and double check all of the buttons.
By the way, I felt like these buttons are not working.
Why is that?
Didn't we set it up?
Show button.
We didn't.
This is weird.
Let's just update this real quick here.
Plus and here plus.
Go UI.
Switch menu to switch to shop.
Settings.
Drag the canvas.
I mean, switch to.
Uh, settings UI.
Now in the settings UI close button hit plus drag canvas.
UI switch to main menu.
Let's find clothes button in the shop.
Plus.
Canvas.
UI switch menu to main menu.
Now we have to start shop.
We can go back settings.
We can go back top to start.
I can play.
I can click.
Pause and pause.
I can click.
Pause.
Go to Main menu and I'm in the main menu again.
Cool.
All right.
That's it for this video.
Let's go to next one.