Hello guys.
Welcome to the video.
In this one I want to show you how to use gamepad to pause the game.
And that will be pretty simple to do.
But before we start, let's go to player input and let's add a new action map just for UI.
I'm going to call it UI.
And this one I'm going to need a pose action.
Let's rename it to a pose and then let's go to player.
Let's open pose.
Let's copy this escape.
Let's go back here and paste it in.
And also I want to copy the gamepad start action and just paste it in here.
Very nice.
Now you.
I will be responsible for pausing the game if we press the button.
And probably we can even remove it from here, actually.
We did not subscribe anything to this one yet.
Let's just go ahead and make it work only with the UI and then we can remove it from the player once
we are sure it is working okay.
Let's go to the scripts.
We need to find UI in game.
And over here I want to make another instance of player controls.
So I'm going to do player input player.
Input.
And then in their wake, we're going to make it equals to a new player input and then make a new instance
of the controls, because I want to disable player controls, but still I want to use UI controls from
the UI in game.
That's why we're doing player input equals to new player input.
So we have two separate instances and one of them will be for player, another one will be for UI.
And then we're going to open on enable.
On enable we're going to do player input enable.
Here.
And also we need player input.
Uh, UI pose performed plus equal CT.
And we're going to call pose button.
Just like that.
We're going to duplicate this.
And on disable we're going to move it here.
And do minus over here just like that.
And also we want to do player input disable.
Okay.
Very, very good.
So now we can pause the game from the UI.
And actually this will work right now let's go and try this.
Let's go back.
Let's go to game mode.
I can press the key button and pause the game.
Same goes for gamepad.
The only issue is I can move my player.
Right.
When game is paused, I can even press jump button and when I unpause the game, my character will jump.
So not cool.
We need to fix it somehow.
And the easiest way would be to disable player controls when we pause the game.
Let's go back to scripts.
And before we do anything over here, I want to wrap this into a method because it's a bit confusing
for me.
Like if game is paused when pausing or pausing the game, it's difficult for me to see.
So I'm going to wrap this into a method extract method.
And this one is an.
And empowers the game.
Then this one pauses the game.
So I'm going to extract method.
Pause the game.
Very good.
This will be a bit easier to understand now.
As before.
I had to think for a couple of seconds what exactly we do in there now, when we pause in the game,
we want to take away controls from the player, and we could make direct reference here and just assign
the reference in the inspector or in the start.
But if you remember, we destroying the player and then we make a new one when we respawn in the player.
So that could be pretty annoying.
Um, to manage.
So here what I'm going to do instead is.
We're going to have private player player.
And then.
Every time we press the button.
I'm going to do player equals to player manager dot instance dot player just like that.
And we want to make uh input available for other scripts so we can go to player.
I'll be here all the way above.
Let's make it public and let's do get private set just like that.
I'm going to save it.
And now it is available for reading, but not for editing from outside of the script and on the UI in
game, when we post the game, we can do player player input disable, and when we unpause the game
we can do player player input enable.
Just that.
And I'm going to save this.
And now we will take away controls from the player when we pause in the game.
And let's go to player input.
And this one indeed can be deleted.
I guess I should not have make it in the first place.
Anyway, let's go to game mode now.
I'm going to take my gamepad.
You can walk around and pose.
I cannot move.
And when I unpause the game, I'm lending.
All right.
Cannot control the character and control the character.
Nice.
Now, the next goal would be to make UI work with the input from a gamepad, because now I cannot select
buttons in the menu.
You can hear I'm clicking the buttons, but menu is not working.
So let's go ahead and fix it.
And we're going to do that in the next video.
I'll see you there.