1
00:00:00,000 --> 00:00:03,800
Welcome back, My favorite game developers.

2
00:00:03,795 --> 00:00:06,105
In this video, we are going to be not

3
00:00:06,105 --> 00:00:08,865
only transitioning to the next level,

4
00:00:08,865 --> 00:00:11,285
we are also going to be transitioning.

5
00:00:11,280 --> 00:00:13,340
They're in a much cooler way.

6
00:00:13,335 --> 00:00:15,215
So now when we walk through the portal,

7
00:00:15,210 --> 00:00:16,320
we don't go immediately.

8
00:00:16,320 --> 00:00:19,580
We wait two seconds and then we go and we can even

9
00:00:19,575 --> 00:00:23,315
adjust this from the level manager as much as we want.

10
00:00:23,310 --> 00:00:24,620
So you can see we have

11
00:00:24,615 --> 00:00:27,585
a central figure now which is the level manager.

12
00:00:27,585 --> 00:00:29,505
We are going to use coroutines,

13
00:00:29,505 --> 00:00:32,735
scene manager, and all of that good stuff.

14
00:00:32,730 --> 00:00:37,390
So let's not waste any more time and let's get started.

15
00:00:37,389 --> 00:00:43,759
Oh, okay, so now we need a level manager because,

16
00:00:43,760 --> 00:00:45,680
okay, It's all fun and games

17
00:00:45,680 --> 00:00:48,250
when the portal is transitioning us.

18
00:00:48,245 --> 00:00:50,695
But when it comes to big games,

19
00:00:50,690 --> 00:00:53,630
we don't want this particular object to be in

20
00:00:53,630 --> 00:00:57,710
control of the way we move through scenes.

21
00:00:57,710 --> 00:01:01,580
It's much better to have the swan determine which level

22
00:01:01,580 --> 00:01:03,350
we want to move through and then

23
00:01:03,350 --> 00:01:05,660
have a more central object,

24
00:01:05,660 --> 00:01:08,390
which is the level manager that will handle

25
00:01:08,390 --> 00:01:11,500
the process of moving us from level to level.

26
00:01:11,495 --> 00:01:13,675
This later on as you grow.

27
00:01:13,670 --> 00:01:16,420
For now, it doesn't have to be like this.

28
00:01:16,415 --> 00:01:18,455
You can simply just use the portal.

29
00:01:18,455 --> 00:01:20,575
The game will work forever.

30
00:01:20,570 --> 00:01:22,450
When it comes to big games,

31
00:01:22,445 --> 00:01:25,225
the actual object doesn't do the job.

32
00:01:25,220 --> 00:01:26,570
You have a more,

33
00:01:26,570 --> 00:01:28,550
let's say a bigger authority,

34
00:01:28,550 --> 00:01:29,930
a bigger head, which is the level

35
00:01:29,930 --> 00:01:31,690
manager that handles that.

36
00:01:31,685 --> 00:01:33,775
So I'm going to right-click create an

37
00:01:33,770 --> 00:01:35,860
empty, reset its position.

38
00:01:35,855 --> 00:01:39,685
And this is going to be the level manager.

39
00:01:39,680 --> 00:01:42,610
You can satisfy wherever you want.

40
00:01:42,605 --> 00:01:44,455
And you can go into the scripts right

41
00:01:44,450 --> 00:01:46,220
here and to the managers,

42
00:01:46,220 --> 00:01:49,130
right-click create C-sharp script.

43
00:01:49,130 --> 00:01:52,010
The level manager.

44
00:01:52,010 --> 00:01:55,780
Hit Enter and wait for it just a little bit

45
00:01:55,775 --> 00:01:57,805
for it to compile

46
00:01:57,800 --> 00:02:00,550
the goal level manager at the scripting here.

47
00:02:00,545 --> 00:02:02,665
And let's go ahead and open it up.

48
00:02:02,660 --> 00:02:05,440
Now, first thing we want to do

49
00:02:05,435 --> 00:02:08,435
is make this level manager and instance.

50
00:02:08,434 --> 00:02:10,074
What is an instance?

51
00:02:10,070 --> 00:02:13,220
The instance will allow us to call upon

52
00:02:13,220 --> 00:02:16,310
this level manager wherever we are and use

53
00:02:16,310 --> 00:02:18,170
what ever valuable as

54
00:02:18,170 --> 00:02:20,290
public and whatever method is

55
00:02:20,285 --> 00:02:22,675
public available to us are created,

56
00:02:22,670 --> 00:02:24,610
make it an instance and then call it,

57
00:02:24,605 --> 00:02:26,995
and you will understand how that works.

58
00:02:26,990 --> 00:02:29,750
So what we can do is first of all,

59
00:02:29,750 --> 00:02:35,450
we're going to make a public static level manager

60
00:02:35,450 --> 00:02:37,480
of that means this variable will be

61
00:02:37,475 --> 00:02:41,135
off type level manager and call this instance.

62
00:02:41,135 --> 00:02:42,805
And then in start,

63
00:02:42,800 --> 00:02:48,670
we are going to set the instance equal to this saved.

64
00:02:48,665 --> 00:02:52,795
Okay, so what is happening right now?

65
00:02:52,790 --> 00:02:54,580
First of all, public,

66
00:02:54,575 --> 00:02:56,945
we know what public is static.

67
00:02:56,945 --> 00:02:58,675
What is static?

68
00:02:58,670 --> 00:03:01,910
Static means that through all of the code,

69
00:03:01,910 --> 00:03:04,120
we will have this the sink.

70
00:03:04,115 --> 00:03:08,095
So whether we call it from the player controller,

71
00:03:08,090 --> 00:03:09,710
from the bullet impact,

72
00:03:09,710 --> 00:03:11,830
from the room manager.

73
00:03:11,825 --> 00:03:14,965
The level manager instance is always

74
00:03:14,960 --> 00:03:17,990
the same throughout when we instantiate the book,

75
00:03:17,990 --> 00:03:21,070
for example, every single bullet is a clone.

76
00:03:21,065 --> 00:03:23,045
Do you remember? So if I run the game,

77
00:03:23,045 --> 00:03:24,755
let me just show you what I mean.

78
00:03:24,755 --> 00:03:27,505
So I shoot a couple of bullets, pause the game.

79
00:03:27,500 --> 00:03:30,190
You can see that each one of them is a clone.

80
00:03:30,185 --> 00:03:34,225
So if I try to access the player bullet controller,

81
00:03:34,220 --> 00:03:36,140
for example, if it's not static,

82
00:03:36,140 --> 00:03:38,180
some variable it will access,

83
00:03:38,180 --> 00:03:39,440
it will be different than,

84
00:03:39,440 --> 00:03:42,790
for example, a variable which is here or here.

85
00:03:42,785 --> 00:03:47,035
But if I create a static variable on the player bullet,

86
00:03:47,030 --> 00:03:50,510
then whichever bullet I access,

87
00:03:50,510 --> 00:03:52,430
the variable which is static,

88
00:03:52,430 --> 00:03:53,620
will be the same.

89
00:03:53,615 --> 00:03:57,695
So static means it's the same throughout all of the gain,

90
00:03:57,695 --> 00:04:00,715
wherever and whenever you access it.

91
00:04:00,710 --> 00:04:03,620
That is very important when it comes to a static.

92
00:04:03,620 --> 00:04:06,200
So it's of type level manager that's

93
00:04:06,200 --> 00:04:09,320
pretty easy to understand and its name is instance.

94
00:04:09,320 --> 00:04:10,760
We can call it whatever we want.

95
00:04:10,760 --> 00:04:12,190
We can call it Michael if you want,

96
00:04:12,185 --> 00:04:13,565
what will keep it as instance.

97
00:04:13,565 --> 00:04:17,485
And then we have this ironically pun intended and what?

98
00:04:17,480 --> 00:04:20,480
We have instance equal this.

99
00:04:20,480 --> 00:04:23,090
This means the actual class.

100
00:04:23,090 --> 00:04:24,320
So we are using

101
00:04:24,320 --> 00:04:26,560
the instance as soon as we start the game.

102
00:04:26,555 --> 00:04:28,985
Instance is this.

103
00:04:28,985 --> 00:04:31,645
So now wherever we are in the code,

104
00:04:31,640 --> 00:04:35,530
we can go ahead and write level manager dot instance,

105
00:04:35,525 --> 00:04:39,275
and access whichever variable which is public obviously,

106
00:04:39,275 --> 00:04:41,015
or method that we have in here.

107
00:04:41,015 --> 00:04:42,835
So next thing we're going to

108
00:04:42,830 --> 00:04:45,170
do is we'll remove the update for now.

109
00:04:45,170 --> 00:04:47,230
Use it will create it again.

110
00:04:47,225 --> 00:04:49,435
And we need to create something

111
00:04:49,430 --> 00:04:53,180
called a serialized field.

112
00:04:53,180 --> 00:04:58,630
Float. And it's going to be the time to load.

113
00:04:58,625 --> 00:05:01,705
So, and it's going to be equal to 2 f.

114
00:05:01,700 --> 00:05:04,030
Why do we create a font load?

115
00:05:04,025 --> 00:05:05,845
What is actually our goal?

116
00:05:05,845 --> 00:05:07,895
Out of all of this, I forgot to tell you.

117
00:05:07,895 --> 00:05:09,745
What we want to do is we want to

118
00:05:09,740 --> 00:05:12,910
delay the transition to the next level,

119
00:05:12,905 --> 00:05:15,545
so we don't want it to happen instantaneously.

120
00:05:15,545 --> 00:05:17,365
We want to have at least two seconds,

121
00:05:17,360 --> 00:05:18,730
so we get to the portal,

122
00:05:18,725 --> 00:05:20,005
we wait two seconds, and

123
00:05:20,000 --> 00:05:22,240
then we traveled on to the next level.

124
00:05:22,235 --> 00:05:25,295
This will just add a bit of us authenticity as you know,

125
00:05:25,295 --> 00:05:27,315
whenever you are playing a game, you don't.

126
00:05:27,315 --> 00:05:30,895
And to report and then immediately start the next level.

127
00:05:30,895 --> 00:05:32,415
You want to have a bit of time,

128
00:05:32,410 --> 00:05:34,590
two seconds maybe rethink your decision,

129
00:05:34,585 --> 00:05:36,435
but it will be over.

130
00:05:36,430 --> 00:05:38,410
And how are we going to do this?

131
00:05:38,410 --> 00:05:42,090
We'll obviously we are going to be using a coating.

132
00:05:42,085 --> 00:05:44,655
So I'm not going to tell you to create

133
00:05:44,650 --> 00:05:47,560
the quarantine right now because you'll need to do with,

134
00:05:47,560 --> 00:05:49,270
I think I do have a challenge

135
00:05:49,270 --> 00:05:51,370
somewhere where you create the coroutine.

136
00:05:51,370 --> 00:05:54,100
So pay attention very closely.

137
00:05:54,100 --> 00:05:55,330
I know called teens are

138
00:05:55,330 --> 00:05:57,490
very hard to learn in the beginning.

139
00:05:57,490 --> 00:06:00,360
Once you get the hang of it, it's extremely easy.

140
00:06:00,355 --> 00:06:02,295
Let's get started. First of all,

141
00:06:02,290 --> 00:06:03,820
because we will be accessing

142
00:06:03,820 --> 00:06:06,060
this co-routine from a different script.

143
00:06:06,055 --> 00:06:09,965
I'm going to write public eye enumerator.

144
00:06:09,960 --> 00:06:13,030
So the coroutine is of type I and numerator.

145
00:06:13,025 --> 00:06:21,485
And we're going to call it the loading next, next level.

146
00:06:21,550 --> 00:06:25,580
And in here we are going to be taking in an argument.

147
00:06:25,580 --> 00:06:28,160
So it's going to be of type string and it's going to be

148
00:06:28,160 --> 00:06:31,570
the next level, just like that.

149
00:06:31,565 --> 00:06:34,675
And in here what we'll do is we want to wait

150
00:06:34,670 --> 00:06:37,810
for the time to load and then load the scene.

151
00:06:37,805 --> 00:06:41,215
So as we said, yield,

152
00:06:41,210 --> 00:06:46,970
return, new, wait four seconds.

153
00:06:46,970 --> 00:06:48,710
And this wait four seconds,

154
00:06:48,710 --> 00:06:53,030
we are going to use the time to load.

155
00:06:53,030 --> 00:06:54,370
How great is that?

156
00:06:54,365 --> 00:06:57,025
And finally, after we wait 42 seconds,

157
00:06:57,020 --> 00:07:02,030
we are going to go into the scene manager.

158
00:07:02,030 --> 00:07:05,720
We add the scene management in

159
00:07:05,720 --> 00:07:09,200
here and now we can access the scene manager.

160
00:07:09,199 --> 00:07:11,529
So did you notice what happened right now?

161
00:07:11,525 --> 00:07:14,755
It didn't allow me to use the scene manager until I

162
00:07:14,750 --> 00:07:18,250
had the criteria telling unity that we are using this.

163
00:07:18,245 --> 00:07:21,395
So Scene Manager, not Unity, excuse me,

164
00:07:21,395 --> 00:07:23,165
the script right here,

165
00:07:23,165 --> 00:07:27,415
this entire file that we are using, seen management.

166
00:07:27,410 --> 00:07:30,520
So Scene Manager, dot load seen.

167
00:07:30,515 --> 00:07:34,595
And as the next scene that we are going to 0 or I mean,

168
00:07:34,595 --> 00:07:38,075
next level that we are going too low. Okay, great.

169
00:07:38,075 --> 00:07:39,985
Now the next thing that we need to do

170
00:07:39,980 --> 00:07:42,140
is we need to go into level exit.

171
00:07:42,140 --> 00:07:44,960
And instead of using the Scene Manager here,

172
00:07:44,960 --> 00:07:49,130
we simply use the instance to start the co-routine.

173
00:07:49,130 --> 00:07:51,980
And honestly, I'm already very tired,

174
00:07:51,980 --> 00:07:55,460
so I think it's better for you to do this instead of me.

175
00:07:55,460 --> 00:07:58,180
So go ahead, start the co-routine.

176
00:07:58,175 --> 00:08:00,755
First of all, from the level of exit script,

177
00:08:00,755 --> 00:08:05,695
Kali, call the level manager and move to the next level.

178
00:08:05,690 --> 00:08:09,350
There is a small trickier you'll need to watch out for.

179
00:08:09,350 --> 00:08:11,380
I'm going to give you a small hint,

180
00:08:11,375 --> 00:08:14,615
which is you can't simply call a co-routine.

181
00:08:14,615 --> 00:08:17,725
You need to start a quality.

182
00:08:17,720 --> 00:08:22,070
So pause the video right now and go start the co-routine.

183
00:08:22,070 --> 00:08:24,170
Oh, okay, welcome back.

184
00:08:24,170 --> 00:08:26,810
So how did you get on with that?

185
00:08:26,810 --> 00:08:29,570
And here I'm going to remove this.

186
00:08:29,570 --> 00:08:31,460
And instead I'm going to say that I'm

187
00:08:31,460 --> 00:08:33,860
going to start a co-routine.

188
00:08:33,860 --> 00:08:37,390
I'm going to use the level manager.

189
00:08:37,385 --> 00:08:40,255
I hope this was not the hardest part if you

190
00:08:40,250 --> 00:08:42,810
did manage to use instance,

191
00:08:42,814 --> 00:08:44,694
I congratulate you, you move

192
00:08:44,690 --> 00:08:46,600
to the next level of game development.

193
00:08:46,595 --> 00:08:48,265
If not, don't worry about it,

194
00:08:48,260 --> 00:08:50,270
it's probably my mistake

195
00:08:50,270 --> 00:08:52,870
because I didn't tell you I didn't give you the hint.

196
00:08:52,865 --> 00:08:56,995
But we are going to be loading next level.

197
00:08:56,990 --> 00:08:58,730
So this method in loading

198
00:08:58,730 --> 00:09:01,700
next level is actually an eye enumerator from

199
00:09:01,700 --> 00:09:03,560
the level manager and it

200
00:09:03,560 --> 00:09:06,850
requires a next level string right here,

201
00:09:06,845 --> 00:09:08,575
as you can see as an argument.

202
00:09:08,570 --> 00:09:10,580
So I'm going to give it to it.

203
00:09:10,580 --> 00:09:12,070
And what should it be?

204
00:09:12,065 --> 00:09:15,055
It should be the level two lot.

205
00:09:15,050 --> 00:09:17,630
Save that. And one very nice thing.

206
00:09:17,630 --> 00:09:20,680
You can see that when we stopped using the scene manager,

207
00:09:20,675 --> 00:09:23,315
the using Unity's engine

208
00:09:23,315 --> 00:09:26,465
is no longer as wide as the Unity engine alone.

209
00:09:26,465 --> 00:09:30,565
So the things that we don't use are a bit grayed out.

210
00:09:30,560 --> 00:09:32,930
So I can actually remove this,

211
00:09:32,930 --> 00:09:34,460
save a bit of memory.

212
00:09:34,460 --> 00:09:37,240
And now the level exit just allocates

213
00:09:37,235 --> 00:09:40,255
or calls the level manager the central head,

214
00:09:40,250 --> 00:09:42,430
and tells it to load the level.

215
00:09:42,425 --> 00:09:44,975
This will come in handy when we have multiple portals.

216
00:09:44,975 --> 00:09:46,265
You'll see, trust me,

217
00:09:46,265 --> 00:09:48,865
it's much better to do it this way.

218
00:09:48,860 --> 00:09:50,140
So save that.

219
00:09:50,135 --> 00:09:53,335
Go back and to our game right here.

220
00:09:53,330 --> 00:09:56,330
Start the game, walked towards the portal.

221
00:09:56,329 --> 00:09:57,619
I'm playing in the scene mode.

222
00:09:57,620 --> 00:09:59,360
So now when I hit the portal,

223
00:09:59,360 --> 00:10:01,880
we should have two seconds before we vote.

224
00:10:01,880 --> 00:10:03,500
And we can see it right here in

225
00:10:03,500 --> 00:10:05,330
London manager time to load two seconds.

226
00:10:05,330 --> 00:10:07,390
So there we go. Here goes nothing.

227
00:10:07,385 --> 00:10:10,985
112 up.

228
00:10:10,985 --> 00:10:11,575
There we go.

229
00:10:11,570 --> 00:10:14,000
So now we are in the level 1

230
00:10:14,000 --> 00:10:16,810
and we didn't go to there immediately.

231
00:10:16,805 --> 00:10:18,295
So I hope you enjoy it.

232
00:10:18,290 --> 00:10:21,010
Make sure to state and all of your changes.

233
00:10:21,005 --> 00:10:23,395
And in the next video we are going to make

234
00:10:23,390 --> 00:10:25,870
the transitions even cooler.

235
00:10:25,865 --> 00:10:28,105
Can you imagine that even cooler than this?

236
00:10:28,100 --> 00:10:30,900
Make sure to leave a review for the cool transitions.

237
00:10:30,904 --> 00:10:32,494
I'll see you then.

