1
00:00:00,000 --> 00:00:03,660
Welcome back, my fellow game developers.

2
00:00:03,660 --> 00:00:06,440
In this video, when we run the game,

3
00:00:06,435 --> 00:00:08,855
when we had the peaky,

4
00:00:08,850 --> 00:00:11,790
you can see that we have a balls menu.

5
00:00:11,790 --> 00:00:14,150
We can either go to the main menu at works,

6
00:00:14,145 --> 00:00:16,415
trust me, or we can resume the game.

7
00:00:16,410 --> 00:00:18,870
If we resume the game, We are back and again,

8
00:00:18,870 --> 00:00:20,640
we can also pause this again,

9
00:00:20,640 --> 00:00:23,880
and instead of clicking on the one of the buttons,

10
00:00:23,880 --> 00:00:25,220
we can hit the peaky.

11
00:00:25,215 --> 00:00:27,485
But we are that this is something

12
00:00:27,480 --> 00:00:29,700
that we'll also cover in the next video.

13
00:00:29,700 --> 00:00:34,620
But for now, let's go ahead and create our pause menu.

14
00:00:34,615 --> 00:00:38,135
Oh, okay, so now we want to

15
00:00:38,135 --> 00:00:41,585
add the ability for our player to pause the game.

16
00:00:41,585 --> 00:00:43,355
Our player, I mean,

17
00:00:43,355 --> 00:00:45,085
the guy that, or the

18
00:00:45,080 --> 00:00:47,500
girl that's actually playing our game.

19
00:00:47,495 --> 00:00:49,235
So how are we going to do this?

20
00:00:49,235 --> 00:00:51,665
Well, it's going to be fairly simple.

21
00:00:51,665 --> 00:00:54,975
We are going to duplicate the depth screen.

22
00:00:54,979 --> 00:00:58,899
And this will be the pause screen or pause menu.

23
00:00:58,895 --> 00:01:03,935
So pause menu and hit Enter.

24
00:01:03,935 --> 00:01:06,655
And here we are going to

25
00:01:06,650 --> 00:01:09,710
have everything the same except for

26
00:01:09,710 --> 00:01:17,900
the let me turn this on except for the lot.

27
00:01:17,900 --> 00:01:19,070
So first of all, the blood,

28
00:01:19,070 --> 00:01:22,090
we don't want the blood and the pause menu,

29
00:01:22,085 --> 00:01:26,005
it will be let me set it on the one.

30
00:01:26,000 --> 00:01:27,890
So we have the image in here,

31
00:01:27,890 --> 00:01:29,650
but we want to make it just a little bit

32
00:01:29,645 --> 00:01:32,125
faded so we can see the background.

33
00:01:32,120 --> 00:01:36,710
So let's say 0.5, okay?

34
00:01:36,710 --> 00:01:38,990
So we will have it at 0.5.

35
00:01:38,990 --> 00:01:42,650
And then we are going to move the restart button.

36
00:01:42,650 --> 00:01:44,900
And you just make the smaller move

37
00:01:44,900 --> 00:01:46,670
the restart button here,

38
00:01:46,670 --> 00:01:49,070
move the main menu here.

39
00:01:49,070 --> 00:01:50,600
And instead of restarting

40
00:01:50,600 --> 00:01:53,240
the level which you can keep if you want,

41
00:01:53,240 --> 00:01:56,680
but we're going to make this one Resume button.

42
00:01:56,675 --> 00:02:01,165
So Resume button and in the text in here

43
00:02:01,160 --> 00:02:08,620
will just resume game.

44
00:02:08,615 --> 00:02:09,985
So there we go.

45
00:02:09,980 --> 00:02:11,300
Now we have these two buttons.

46
00:02:11,300 --> 00:02:12,710
Obviously we'll need to change

47
00:02:12,710 --> 00:02:14,360
the functionalities and here.

48
00:02:14,360 --> 00:02:17,240
But that's something and I couple of minutes.

49
00:02:17,240 --> 00:02:20,020
First of all, let's open up the UI Manager.

50
00:02:20,015 --> 00:02:23,065
And in here we are going to do a couple of things.

51
00:02:23,060 --> 00:02:25,640
First of all, obviously we need a reference.

52
00:02:25,640 --> 00:02:27,140
So I'm going to create

53
00:02:27,140 --> 00:02:30,710
a serialized field of the game object,

54
00:02:30,709 --> 00:02:34,329
which is the pause menu.

55
00:02:34,325 --> 00:02:35,555
Save that.

56
00:02:35,555 --> 00:02:37,465
But the thing here is,

57
00:02:37,460 --> 00:02:41,540
as we've said in the previous video, UI Manager, okay,

58
00:02:41,540 --> 00:02:44,560
maybe he does turn on and off the pause menu,

59
00:02:44,555 --> 00:02:48,575
but he is not responsible for actually pausing the game.

60
00:02:48,575 --> 00:02:50,995
The level manager is the script

61
00:02:50,990 --> 00:02:54,020
that is responsible for doing that.

62
00:02:54,020 --> 00:02:56,060
So in the level manager,

63
00:02:56,060 --> 00:03:01,630
we are going to create a public bool.

64
00:03:01,625 --> 00:03:03,355
And we're going to call this,

65
00:03:03,350 --> 00:03:05,510
the game is paused.

66
00:03:05,510 --> 00:03:07,910
And obviously I don't want to make it public,

67
00:03:07,910 --> 00:03:10,180
but we are going to be using it a lot.

68
00:03:10,175 --> 00:03:12,265
You know what? Let's not make it public.

69
00:03:12,260 --> 00:03:14,840
Let's make it a private variable,

70
00:03:14,840 --> 00:03:16,880
and we'll create a way to access.

71
00:03:16,880 --> 00:03:24,070
So a public bool is game paused,

72
00:03:24,065 --> 00:03:26,735
and we'll just return.

73
00:03:26,735 --> 00:03:30,895
So these are sometimes a bit cumbersome.

74
00:03:30,890 --> 00:03:32,140
Maybe you're thinking, Well,

75
00:03:32,135 --> 00:03:33,985
I'm creating a lot of gold.

76
00:03:33,980 --> 00:03:36,800
But trust me, when you get to the higher levels,

77
00:03:36,800 --> 00:03:38,110
to the professional level,

78
00:03:38,105 --> 00:03:40,135
these are essential things to have.

79
00:03:40,130 --> 00:03:41,530
Don't want your game to be

80
00:03:41,525 --> 00:03:43,735
easily corruptible through the code.

81
00:03:43,730 --> 00:03:47,510
So now that we have the game is paused until I manager we

82
00:03:47,510 --> 00:03:49,160
have the pause menu we

83
00:03:49,160 --> 00:03:51,980
obviously want to access in some way,

84
00:03:51,980 --> 00:03:53,060
change the pause menu.

85
00:03:53,060 --> 00:03:57,680
So I'm going to create a method in here that is going to

86
00:03:57,680 --> 00:04:02,840
say that public void turn,

87
00:04:02,840 --> 00:04:06,580
pause, menu on, off.

88
00:04:06,575 --> 00:04:09,145
And it will take in a boolean which is

89
00:04:09,140 --> 00:04:12,400
going to be the on, off.

90
00:04:12,395 --> 00:04:14,275
And I know this is not

91
00:04:14,270 --> 00:04:16,340
the best way to represent the variable,

92
00:04:16,340 --> 00:04:19,370
but anyways, let's continue on. You'll see what I mean.

93
00:04:19,370 --> 00:04:21,230
So in here we'll just going

94
00:04:21,230 --> 00:04:24,020
to go ahead and get the pause menu,

95
00:04:24,020 --> 00:04:28,160
dots directive to on, off.

96
00:04:28,160 --> 00:04:32,450
So now we go back into the level manager.

97
00:04:32,450 --> 00:04:37,580
And in here we are going to create a public void.

98
00:04:37,580 --> 00:04:42,740
Pause, Resume game.

99
00:04:42,740 --> 00:04:46,150
And what we'll do in here is we're going to check

100
00:04:46,145 --> 00:04:49,285
if we are not in the game paused.

101
00:04:49,280 --> 00:04:51,050
So we haven't paused yet.

102
00:04:51,050 --> 00:04:53,770
Then we'll access the UI Manager.

103
00:04:53,765 --> 00:04:57,525
Dot instance, dot, pause,

104
00:04:57,529 --> 00:04:59,409
turn, pause menu on and off.

105
00:04:59,405 --> 00:05:00,725
And what shall we set it?

106
00:05:00,725 --> 00:05:03,115
Well, we will just set it to true.

107
00:05:03,110 --> 00:05:07,330
Because if we are not unopposed game,

108
00:05:07,325 --> 00:05:09,715
when we press some kind of key,

109
00:05:09,710 --> 00:05:12,610
then we want to turn on the pause menu.

110
00:05:12,605 --> 00:05:14,125
And else.

111
00:05:14,120 --> 00:05:17,270
That means if we haven't paused the game.

112
00:05:17,270 --> 00:05:19,460
So if we or excuse me,

113
00:05:19,460 --> 00:05:21,410
if we are in a paused game.

114
00:05:21,410 --> 00:05:24,100
Then we are going to do the same in here,

115
00:05:24,095 --> 00:05:26,875
but instead we are going to turn it off.

116
00:05:26,870 --> 00:05:29,300
And this will go to the UI Manager axis,

117
00:05:29,300 --> 00:05:30,890
this one and turn it off.

118
00:05:30,890 --> 00:05:32,630
So with that out of the way,

119
00:05:32,630 --> 00:05:34,070
there is something that we still

120
00:05:34,070 --> 00:05:35,860
need to do and that is actually

121
00:05:35,855 --> 00:05:38,335
turn or change this game

122
00:05:38,330 --> 00:05:40,490
as opposed using some kind of button.

123
00:05:40,490 --> 00:05:42,890
And this is going to be your challenge to

124
00:05:42,890 --> 00:05:45,790
resume the game using some kind of key.

125
00:05:45,785 --> 00:05:48,295
So check for inputs and when pressed,

126
00:05:48,290 --> 00:05:51,560
we should call the method and resume gain or pause

127
00:05:51,560 --> 00:05:55,480
the game and make sure to change the status of the game.

128
00:05:55,475 --> 00:05:58,415
So if it's paused or if it's not anymore,

129
00:05:58,415 --> 00:06:02,195
so pause the video right now and go create an input.

130
00:06:02,195 --> 00:06:04,015
Okay, welcome back.

131
00:06:04,010 --> 00:06:05,650
So where do you want to put it?

132
00:06:05,645 --> 00:06:07,835
I think up here.

133
00:06:07,835 --> 00:06:09,995
So an update, we are going to check

134
00:06:09,995 --> 00:06:15,875
if input dot get key down

135
00:06:15,875 --> 00:06:20,125
and a key code for p.

136
00:06:20,120 --> 00:06:26,170
Then we are going to pause, resume, the game.

137
00:06:26,165 --> 00:06:28,945
It's that simple. And then end here.

138
00:06:28,940 --> 00:06:30,910
If we haven't paused the game,

139
00:06:30,905 --> 00:06:33,005
so the gain is not paused.

140
00:06:33,005 --> 00:06:36,265
We click the peaky, we turned on.

141
00:06:36,260 --> 00:06:37,610
So the turn on,

142
00:06:37,610 --> 00:06:39,160
turn off is true.

143
00:06:39,155 --> 00:06:44,655
So in here we are going to say that the game is paused,

144
00:06:44,655 --> 00:06:47,215
is equal to true.

145
00:06:47,940 --> 00:06:53,020
And duplicate this and move this down here.

146
00:06:53,020 --> 00:06:54,640
False.

147
00:06:54,640 --> 00:06:55,990
Save that.

148
00:06:55,990 --> 00:06:57,550
So let's test this out.

149
00:06:57,550 --> 00:07:01,290
I hope I didn't make a mistake with the false and true.

150
00:07:01,285 --> 00:07:03,525
Why I believe it's correct.

151
00:07:03,520 --> 00:07:05,380
So in the Resume button

152
00:07:05,380 --> 00:07:07,630
and we're going to add something in here,

153
00:07:07,630 --> 00:07:10,350
which is the UI canvas.

154
00:07:10,345 --> 00:07:13,795
And inhere we are going to go to the UI Manager.

155
00:07:13,795 --> 00:07:16,215
We are going to find turn,

156
00:07:16,210 --> 00:07:17,730
pause menu on, off.

157
00:07:17,725 --> 00:07:19,605
And as you can see, we have the option

158
00:07:19,600 --> 00:07:21,810
to add either true or false.

159
00:07:21,805 --> 00:07:24,285
And this is the actual boolean right

160
00:07:24,280 --> 00:07:27,390
here that turns on all of the paths.

161
00:07:27,390 --> 00:07:30,080
So back in our game and here,

162
00:07:30,080 --> 00:07:34,750
let's first of all turn of the pause menu, run the game.

163
00:07:34,745 --> 00:07:37,715
So and here we have the peaky.

164
00:07:37,715 --> 00:07:39,955
We can go back to the main menu.

165
00:07:39,950 --> 00:07:45,140
We can also hit the peaky than had the peaky back.

166
00:07:45,140 --> 00:07:47,170
And then we turn off the pause menu.

167
00:07:47,165 --> 00:07:49,045
There we go. But there is still one thing

168
00:07:49,040 --> 00:07:50,990
which is the Resume button.

169
00:07:50,990 --> 00:07:53,240
Now I'm going to go ahead

170
00:07:53,240 --> 00:07:55,810
and add the onclick event in here.

171
00:07:55,805 --> 00:07:58,855
And I'm going to break my own rule of adding

172
00:07:58,850 --> 00:08:01,070
the level manager from

173
00:08:01,070 --> 00:08:04,490
the manager's everybody right now is like,

174
00:08:04,490 --> 00:08:06,990
Oh, don't break the rules.

175
00:08:06,994 --> 00:08:09,024
But yes I am.

176
00:08:09,020 --> 00:08:15,310
I'm going to go into the restored pause resume game.

177
00:08:15,305 --> 00:08:17,035
So run the game.

178
00:08:17,030 --> 00:08:19,010
And now we are going to press the key,

179
00:08:19,010 --> 00:08:21,310
resume the game, and everything works fine.

180
00:08:21,305 --> 00:08:23,285
But as you can see, if I pause the game,

181
00:08:23,285 --> 00:08:24,725
I can still walk around.

182
00:08:24,725 --> 00:08:27,505
I can still shoot enemies and I can still die.

183
00:08:27,500 --> 00:08:30,920
Now, if you want to create a dark souls ask

184
00:08:30,920 --> 00:08:32,630
type of pausing in

185
00:08:32,630 --> 00:08:35,080
the game where the game continues in the background.

186
00:08:35,075 --> 00:08:37,555
And you just sit there helplessly trying to

187
00:08:37,550 --> 00:08:40,100
figure out what's happening in the menu. Be my guest.

188
00:08:40,100 --> 00:08:42,290
If not, if you want the world stopped,

189
00:08:42,290 --> 00:08:45,070
then continue on to the next video.

190
00:08:45,065 --> 00:08:46,645
But before we do that, obviously

191
00:08:46,640 --> 00:08:48,410
will need to commit our changes.

192
00:08:48,410 --> 00:08:50,910
So see you then.

