WEBVTT

00:00.020 --> 00:00.470
Hello guys.

00:00.470 --> 00:01.400
Welcome to the video.

00:01.400 --> 00:05.240
In this one I want to show you how to use gamepad to pause the game.

00:05.240 --> 00:07.460
And that will be pretty simple to do.

00:07.460 --> 00:13.700
But before we start, let's go to player input and let's add a new action map just for UI.

00:13.730 --> 00:15.230
I'm going to call it UI.

00:15.230 --> 00:18.050
And this one I'm going to need a pose action.

00:18.050 --> 00:22.970
Let's rename it to a pose and then let's go to player.

00:23.180 --> 00:24.140
Let's open pose.

00:24.140 --> 00:25.880
Let's copy this escape.

00:25.880 --> 00:28.880
Let's go back here and paste it in.

00:28.880 --> 00:33.260
And also I want to copy the gamepad start action and just paste it in here.

00:34.760 --> 00:35.630
Very nice.

00:35.630 --> 00:36.410
Now you.

00:36.410 --> 00:39.590
I will be responsible for pausing the game if we press the button.

00:39.590 --> 00:44.060
And probably we can even remove it from here, actually.

00:45.440 --> 00:47.720
We did not subscribe anything to this one yet.

00:47.720 --> 00:52.100
Let's just go ahead and make it work only with the UI and then we can remove it from the player once

00:52.100 --> 00:54.080
we are sure it is working okay.

00:56.070 --> 00:57.360
Let's go to the scripts.

00:58.640 --> 01:00.560
We need to find UI in game.

01:01.960 --> 01:05.410
And over here I want to make another instance of player controls.

01:05.410 --> 01:07.780
So I'm going to do player input player.

01:09.440 --> 01:10.160
Input.

01:10.880 --> 01:15.920
And then in their wake, we're going to make it equals to a new player input and then make a new instance

01:15.920 --> 01:21.440
of the controls, because I want to disable player controls, but still I want to use UI controls from

01:21.440 --> 01:22.490
the UI in game.

01:22.490 --> 01:25.280
That's why we're doing player input equals to new player input.

01:25.280 --> 01:30.290
So we have two separate instances and one of them will be for player, another one will be for UI.

01:30.290 --> 01:34.700
And then we're going to open on enable.

01:37.070 --> 01:40.340
On enable we're going to do player input enable.

01:41.270 --> 01:41.780
Here.

01:41.780 --> 01:44.210
And also we need player input.

01:44.660 --> 01:49.610
Uh, UI pose performed plus equal CT.

01:49.820 --> 01:52.310
And we're going to call pose button.

01:53.340 --> 01:54.120
Just like that.

01:54.120 --> 01:55.800
We're going to duplicate this.

01:56.280 --> 01:59.970
And on disable we're going to move it here.

02:02.070 --> 02:04.710
And do minus over here just like that.

02:04.710 --> 02:08.070
And also we want to do player input disable.

02:08.680 --> 02:09.400
Okay.

02:10.040 --> 02:11.210
Very, very good.

02:11.210 --> 02:13.610
So now we can pause the game from the UI.

02:13.970 --> 02:17.420
And actually this will work right now let's go and try this.

02:17.420 --> 02:18.500
Let's go back.

02:19.700 --> 02:21.050
Let's go to game mode.

02:22.280 --> 02:25.550
I can press the key button and pause the game.

02:25.550 --> 02:27.320
Same goes for gamepad.

02:27.350 --> 02:30.080
The only issue is I can move my player.

02:31.080 --> 02:31.470
Right.

02:31.470 --> 02:36.810
When game is paused, I can even press jump button and when I unpause the game, my character will jump.

02:36.810 --> 02:38.220
So not cool.

02:38.220 --> 02:39.810
We need to fix it somehow.

02:39.810 --> 02:44.190
And the easiest way would be to disable player controls when we pause the game.

02:44.190 --> 02:45.690
Let's go back to scripts.

02:46.020 --> 02:51.300
And before we do anything over here, I want to wrap this into a method because it's a bit confusing

02:51.300 --> 02:51.870
for me.

02:51.870 --> 02:55.980
Like if game is paused when pausing or pausing the game, it's difficult for me to see.

02:55.980 --> 03:00.330
So I'm going to wrap this into a method extract method.

03:00.330 --> 03:02.580
And this one is an.

03:04.500 --> 03:06.150
And empowers the game.

03:06.330 --> 03:08.040
Then this one pauses the game.

03:08.040 --> 03:10.050
So I'm going to extract method.

03:10.350 --> 03:12.180
Pause the game.

03:12.180 --> 03:13.290
Very good.

03:13.560 --> 03:16.410
This will be a bit easier to understand now.

03:18.830 --> 03:19.370
As before.

03:19.370 --> 03:24.170
I had to think for a couple of seconds what exactly we do in there now, when we pause in the game,

03:24.170 --> 03:30.140
we want to take away controls from the player, and we could make direct reference here and just assign

03:30.140 --> 03:33.260
the reference in the inspector or in the start.

03:33.260 --> 03:38.240
But if you remember, we destroying the player and then we make a new one when we respawn in the player.

03:38.240 --> 03:40.100
So that could be pretty annoying.

03:40.190 --> 03:42.290
Um, to manage.

03:42.290 --> 03:45.710
So here what I'm going to do instead is.

03:46.690 --> 03:49.840
We're going to have private player player.

03:50.200 --> 03:51.370
And then.

03:52.030 --> 03:54.040
Every time we press the button.

03:54.830 --> 04:00.410
I'm going to do player equals to player manager dot instance dot player just like that.

04:00.860 --> 04:07.850
And we want to make uh input available for other scripts so we can go to player.

04:08.900 --> 04:10.940
I'll be here all the way above.

04:15.540 --> 04:20.760
Let's make it public and let's do get private set just like that.

04:21.120 --> 04:22.020
I'm going to save it.

04:22.020 --> 04:28.590
And now it is available for reading, but not for editing from outside of the script and on the UI in

04:28.590 --> 04:34.920
game, when we post the game, we can do player player input disable, and when we unpause the game

04:34.920 --> 04:38.190
we can do player player input enable.

04:38.740 --> 04:39.640
Just that.

04:40.700 --> 04:41.990
And I'm going to save this.

04:41.990 --> 04:45.650
And now we will take away controls from the player when we pause in the game.

04:46.160 --> 04:47.780
And let's go to player input.

04:47.780 --> 04:49.790
And this one indeed can be deleted.

04:49.790 --> 04:52.580
I guess I should not have make it in the first place.

04:53.410 --> 04:55.690
Anyway, let's go to game mode now.

04:57.260 --> 04:58.550
I'm going to take my gamepad.

04:58.580 --> 05:00.830
You can walk around and pose.

05:00.860 --> 05:02.060
I cannot move.

05:03.050 --> 05:05.630
And when I unpause the game, I'm lending.

05:09.170 --> 05:09.830
All right.

05:11.540 --> 05:14.240
Cannot control the character and control the character.

05:14.270 --> 05:14.960
Nice.

05:14.990 --> 05:20.000
Now, the next goal would be to make UI work with the input from a gamepad, because now I cannot select

05:20.000 --> 05:21.020
buttons in the menu.

05:21.020 --> 05:24.950
You can hear I'm clicking the buttons, but menu is not working.

05:24.950 --> 05:26.750
So let's go ahead and fix it.

05:26.750 --> 05:28.580
And we're going to do that in the next video.

05:28.940 --> 05:29.600
I'll see you there.
