1
00:00:03,310 --> 00:00:03,820
In his lecture.

2
00:00:03,820 --> 00:00:08,170
We're hooking up our level portals so we can wait for a moment and then load to the next level.

3
00:00:08,200 --> 00:00:11,170
In its price folder, you should have an exit says exit pixelated.

4
00:00:11,170 --> 00:00:13,480
Yet another piece of amazing Rick Art.

5
00:00:13,510 --> 00:00:19,180
If you jump over in the hierarchy, right click to the object sprites and a square.

6
00:00:19,210 --> 00:00:21,610
You can rename that to be exit.

7
00:00:21,610 --> 00:00:25,810
And then in exit where we're looking for the sprite renderer instead of the Sprite brings square, we

8
00:00:25,810 --> 00:00:29,560
will drag over our exit and then we go for exit pixelated.

9
00:00:29,560 --> 00:00:34,180
We can't see it at the moment because of our sorting layers, so up to layer and we will change the

10
00:00:34,180 --> 00:00:38,620
layer that we need a new layer for these things or can we just put it on something else?

11
00:00:38,620 --> 00:00:39,760
You know, we'll add a new layer.

12
00:00:39,760 --> 00:00:43,930
I don't really like having thousands of layers in here, but in a way it's kind of safer.

13
00:00:43,930 --> 00:00:46,510
And we'll call this interactive walls.

14
00:00:46,510 --> 00:00:49,570
Things that you can bump into is interact bubbles or eyeballs.

15
00:00:49,660 --> 00:00:53,140
Eyeballs that doesn't quite look right, does it, with an A, I believe.

16
00:00:53,140 --> 00:00:55,440
Let's run with that and I'll copy that.

17
00:00:55,450 --> 00:00:59,350
I'm going to head over to exit again, change the layer to be interactive tiles.

18
00:00:59,350 --> 00:01:04,330
Now I also need to click back on this one more time, add a layer and here we find the sorting layers,

19
00:01:04,330 --> 00:01:06,280
click on plus and I will pop in.

20
00:01:06,280 --> 00:01:09,370
Interactive tools will have that just below.

21
00:01:09,370 --> 00:01:10,360
The player I think is fine.

22
00:01:10,360 --> 00:01:12,250
Will the enemies run in front or behind?

23
00:01:12,250 --> 00:01:18,250
Probably the enemies in front because that's what you need to know about just in case we can play around

24
00:01:18,250 --> 00:01:18,490
with that.

25
00:01:18,490 --> 00:01:19,810
But that seems okay for now.

26
00:01:19,810 --> 00:01:20,860
So interactive tools there.

27
00:01:20,860 --> 00:01:24,640
Once again, click back on exit and find our sorting layer interactive tools.

28
00:01:24,640 --> 00:01:27,820
This has been a lot of layers and stuff in this section of the course, hasn't it?

29
00:01:27,820 --> 00:01:29,950
But good to practice with these things now.

30
00:01:29,950 --> 00:01:30,670
It's a bit huge.

31
00:01:30,670 --> 00:01:31,690
I think it might be.

32
00:01:31,690 --> 00:01:36,190
So we'll change the scale to 0.25 and 0.25.

33
00:01:36,190 --> 00:01:37,270
That's a little bit small now.

34
00:01:37,270 --> 00:01:44,110
So I guess 0.5 is the happy medium .5.5 and then drag that over to the right hand side and good.

35
00:01:44,110 --> 00:01:46,990
Now we need to add a box collider so we have a way of bumping into it.

36
00:01:46,990 --> 00:01:50,560
Add component box collider to DX will make this a trigger.

37
00:01:50,590 --> 00:01:52,000
It's going to be triggering things.

38
00:01:52,000 --> 00:01:56,320
And then final step find our prefabs, drag our exit down into prefabs.

39
00:01:56,350 --> 00:01:57,520
That should be pretty good.

40
00:01:57,520 --> 00:01:59,570
Now we need some behavior for this.

41
00:01:59,600 --> 00:02:01,000
I'll hop into my scripts folder.

42
00:02:01,000 --> 00:02:06,610
Right click, create a C-sharp script and I'll call this level exit.

43
00:02:07,980 --> 00:02:14,710
And I'll click into the exit prefab and then drag the level exit over to the add component area.

44
00:02:14,730 --> 00:02:17,570
Now the level exit is on our exit prefab.

45
00:02:17,580 --> 00:02:18,380
Good stuff.

46
00:02:18,390 --> 00:02:20,460
Now let's double click to open up level exit.

47
00:02:20,490 --> 00:02:23,340
I'm not going to need start or update on this.

48
00:02:23,610 --> 00:02:26,690
And you know, what I might do might give this to you as a challenge.

49
00:02:26,700 --> 00:02:30,930
But before I give you the challenge, I'm going to teach you one more thing, which is routines.

50
00:02:30,930 --> 00:02:34,710
And routines are another way for us to create a delay in our game.

51
00:02:34,710 --> 00:02:38,850
So it's going to be really useful to make sure when we touch out exit, we can wait for a moment, say

52
00:02:38,850 --> 00:02:41,430
a second before we load the next scene.

53
00:02:41,430 --> 00:02:47,700
And the core concept here to understand is that we start a process now as we start our routine, and

54
00:02:47,700 --> 00:02:52,770
we do that in the same sort of way that we would call a method, and then we go off and do other things

55
00:02:52,770 --> 00:02:56,100
we yield until our condition is met.

56
00:02:56,100 --> 00:02:59,430
So until, for example, our one or 2 seconds is met.

57
00:02:59,430 --> 00:03:01,320
So that's the general core concept.

58
00:03:01,320 --> 00:03:04,080
Let me give you the code, which I think will make it a bit clearer.

59
00:03:04,080 --> 00:03:07,830
So here's an example or the framework for code, routine code.

60
00:03:07,830 --> 00:03:12,720
We need to call our code routine at some point the same way we call a method, but with some different

61
00:03:12,720 --> 00:03:13,410
wording in here.

62
00:03:13,410 --> 00:03:19,290
So we need to use the word start routine and then we put in parentheses the name of the method.

63
00:03:19,290 --> 00:03:23,970
So if we weren't using a code routine and we didn't use a delay, we might just create a method, and

64
00:03:23,970 --> 00:03:27,480
then the method might just be load the next level and that'd be fine.

65
00:03:27,480 --> 00:03:28,470
We just load the next level.

66
00:03:28,470 --> 00:03:33,150
But if we want to delay, we need to use stock code routine and then load the next level.

67
00:03:33,150 --> 00:03:38,700
And so that's the structure of calling it in terms of the actual construction of our method or our routine,

68
00:03:38,700 --> 00:03:43,860
which is what we're creating when you need to use the keyword I enumerator and then the name of the

69
00:03:43,860 --> 00:03:48,270
method so we won't have a return type, we're not going to have void, we're not going to have bool

70
00:03:48,270 --> 00:03:49,560
or anything like that in there.

71
00:03:49,560 --> 00:03:53,460
We just use the word I enumerator and that enumerates three things.

72
00:03:53,460 --> 00:03:57,090
It keeps a list of things you don't need to worry about the fundamentals of exactly what's happening

73
00:03:57,090 --> 00:03:58,200
under the hood at this stage.

74
00:03:58,200 --> 00:04:03,840
This is just a basic implementation of a code routine, but we need the word enumerator and then the

75
00:04:03,840 --> 00:04:04,740
name of the method.

76
00:04:04,740 --> 00:04:07,230
So for example, load the next scene or whatever you want to call it.

77
00:04:07,230 --> 00:04:13,740
And then in our curly braces, we start off with these very important keywords yield, return, new,

78
00:04:13,740 --> 00:04:19,110
and then we have some options for what we're waiting on or how long we wait or what it is, what the

79
00:04:19,110 --> 00:04:20,519
condition is that's met.

80
00:04:20,519 --> 00:04:24,570
You can create other methods in here that have other conditions in it, but we're going to use one of

81
00:04:24,570 --> 00:04:28,980
the basics, which is wait 4 seconds or I'm going to use wait 4 seconds, real time.

82
00:04:28,980 --> 00:04:30,330
You can use wait 4 seconds.

83
00:04:30,350 --> 00:04:35,610
There's not going to make much of a difference for us, but wait 4 seconds real time and then in parentheses,

84
00:04:35,610 --> 00:04:39,120
the amount of time and you want a parameter rise, the time is put in there.

85
00:04:39,120 --> 00:04:41,460
Say 1/2, that'd be fine.

86
00:04:41,460 --> 00:04:43,590
But you want a variable so you can tune the amount of time.

87
00:04:43,590 --> 00:04:48,240
So this whole line in here, I know it's a little bit crazy, some new words in there, but this whole

88
00:04:48,240 --> 00:04:51,780
line is just basically saying, wait for some stuff to happen.

89
00:04:51,780 --> 00:04:56,490
And when that stuff has happened, then continue on with anything else you want to do after you've waited.

90
00:04:56,490 --> 00:04:58,170
So this line is important.

91
00:04:58,170 --> 00:05:00,240
You can have stuff before this line.

92
00:05:00,240 --> 00:05:01,450
So I could do a couple of things.

93
00:05:01,450 --> 00:05:04,260
So as soon as I call the method, I could play a sound effect.

94
00:05:04,260 --> 00:05:09,450
I could trigger some particle effects, then I could say yield, which means go off and do your other

95
00:05:09,450 --> 00:05:12,780
things you need to do and then return when this condition is met.

96
00:05:12,780 --> 00:05:16,980
Return when you've waited for a certain amount of time and then do the other stuff, which would be

97
00:05:16,980 --> 00:05:18,840
loading the next scene.

98
00:05:18,840 --> 00:05:19,440
So there we go.

99
00:05:19,440 --> 00:05:23,850
It's a slightly different way of introducing a concept where I'm introducing the theory, introducing

100
00:05:23,850 --> 00:05:27,750
the code, and then I'm going to give this to you as a challenge to incorporate this.

101
00:05:27,750 --> 00:05:30,030
The challenge is to load the next level.

102
00:05:30,030 --> 00:05:34,770
When the player touches the exit load the next level, there's a few steps you need to do in this.

103
00:05:34,770 --> 00:05:38,760
We've done this in other sections of the course, so feel free to go check those if you're not exactly

104
00:05:38,760 --> 00:05:39,210
sure.

105
00:05:39,210 --> 00:05:43,950
And for bonus points, wait for a second before loading the next level.

106
00:05:43,950 --> 00:05:44,550
So there you go.

107
00:05:44,580 --> 00:05:45,240
There's your bonus.

108
00:05:45,240 --> 00:05:47,670
If you're feeling a little bit more advanced, there's your challenge.

109
00:05:47,700 --> 00:05:49,230
Take that on C back in when you're done.

110
00:05:51,980 --> 00:05:55,650
Now, any time we're doing loading of stuff, I often forget this.

111
00:05:55,680 --> 00:05:56,270
I'm going to do this.

112
00:05:56,270 --> 00:06:02,930
First of all, I'm going to jump over to file build settings and then I need to go to my scenes, my

113
00:06:02,930 --> 00:06:09,080
levels drag Oh, these will highlight all these 1 to 3, drag them over into scenes in build 1 to 3.

114
00:06:09,080 --> 00:06:09,860
They're in the wrong order.

115
00:06:09,860 --> 00:06:15,410
So I'm going to reorder them, drag one to the top if I can, and then two and then three.

116
00:06:15,410 --> 00:06:15,890
One, two, three.

117
00:06:15,890 --> 00:06:19,250
And that's going to represent zero one and two as our scene index.

118
00:06:19,250 --> 00:06:19,640
Okay.

119
00:06:19,640 --> 00:06:20,330
We've got that.

120
00:06:20,330 --> 00:06:21,740
Now back over into our script.

121
00:06:21,740 --> 00:06:27,920
First of all, we need an on trigger into to DH get rid of the private don't need it tidy things up

122
00:06:27,920 --> 00:06:32,480
a little bit here so I'll do this the simple way first then I'll add something to give us a little bit

123
00:06:32,480 --> 00:06:33,230
of a delay.

124
00:06:33,230 --> 00:06:38,720
So within here I'm going to first of all find what our scene is.

125
00:06:38,720 --> 00:06:44,000
So I need to have some sort of variable I can use var for this when I don't know exactly which variable.

126
00:06:44,010 --> 00:06:48,800
So var current scene index.

127
00:06:49,470 --> 00:06:50,940
It's going to equal what?

128
00:06:50,940 --> 00:06:54,780
Scene Manager Well, we can't see that at the moment because we're not using that namespace.

129
00:06:54,780 --> 00:07:02,130
So let's add using unity engine dot scene management semicolon.

130
00:07:02,130 --> 00:07:06,870
Now when we jump back over here into scene equals scene, we should have some options.

131
00:07:06,870 --> 00:07:08,010
Scene Manager That's what we want.

132
00:07:08,010 --> 00:07:11,760
Scene Manager Dot We need to be figuring out what the active scene at the moment.

133
00:07:11,760 --> 00:07:15,660
So we'll find a method which is get active scene, that's the one in parentheses.

134
00:07:15,660 --> 00:07:18,300
And then in particular we're looking for the build index.

135
00:07:18,300 --> 00:07:22,260
So the build index we're looking at before you've probably done this before, so you know what I'm talking

136
00:07:22,260 --> 00:07:27,060
about, but this is the build index zero one or two at the moment, and that is going to be accessed

137
00:07:27,060 --> 00:07:29,640
by build index at the end and then semicolon.

138
00:07:29,640 --> 00:07:35,370
So that will be stored in this current scene index, which is some sort of variable which if we mouse

139
00:07:35,370 --> 00:07:36,960
over this says that it's an int.

140
00:07:36,960 --> 00:07:41,340
So in current scene index we could call this an int because we know it's an integer, it's going to

141
00:07:41,340 --> 00:07:42,480
be a01 or two.

142
00:07:42,480 --> 00:07:46,080
So at the time when I created it, I wasn't thinking, I didn't want to have to try to figure out is

143
00:07:46,080 --> 00:07:47,910
this an int or a float or something else?

144
00:07:47,910 --> 00:07:53,880
So I just added var and unity figured it out for us, but I can now add int and everyone's happy.

145
00:07:53,880 --> 00:07:57,240
And then when we hit this trigger we want to be loading the next one.

146
00:07:57,240 --> 00:08:00,450
So basically it's whatever our index is now plus one.

147
00:08:00,450 --> 00:08:05,790
So we will tap into our scene manager class once again and we need to load scene.

148
00:08:05,790 --> 00:08:07,200
So that's the method we're calling.

149
00:08:07,200 --> 00:08:08,520
What scene do we want to load?

150
00:08:08,520 --> 00:08:09,390
In our parentheses?

151
00:08:09,390 --> 00:08:14,490
We're going to use our current scene index plus one and semicolon.

152
00:08:14,490 --> 00:08:15,230
Let's save that.

153
00:08:15,250 --> 00:08:17,640
See if this is going to play nicely for us.

154
00:08:17,880 --> 00:08:18,810
I need you anymore.

155
00:08:18,810 --> 00:08:20,150
Click on play.

156
00:08:20,700 --> 00:08:22,320
Run, run, run, run, run, run.

157
00:08:22,320 --> 00:08:25,140
And then think it's going to load the next level, which is pretty cool.

158
00:08:25,140 --> 00:08:25,860
You could leave it at that.

159
00:08:25,860 --> 00:08:27,180
You could have instant loading.

160
00:08:27,180 --> 00:08:28,080
Not a problem.

161
00:08:28,080 --> 00:08:33,059
What I'd like to do is to add a little bit of a delay in here, and the way I'll do that is using a

162
00:08:33,059 --> 00:08:34,080
code routine.

163
00:08:34,080 --> 00:08:39,000
So when we hit our trigger, instead of just saying, do this stuff, we're going to start our code

164
00:08:39,000 --> 00:08:40,200
routine at this point.

165
00:08:40,200 --> 00:08:44,400
So a little bit of space start cur routine and we're going to give it a name.

166
00:08:44,400 --> 00:08:52,170
The name I will give it will be load next level seems to make sense and then parentheses at the end

167
00:08:52,170 --> 00:08:53,070
semicolon.

168
00:08:53,070 --> 00:08:54,840
Now load next level doesn't exist.

169
00:08:54,840 --> 00:09:01,980
So I'm going to highlight all of my code cut that because I need to paste it in, tidy up my formatting

170
00:09:01,980 --> 00:09:08,130
a little bit, jump down below and code routines need I enumerators for them to work so we jump into

171
00:09:08,130 --> 00:09:12,990
our I enumerator and this will be called load next level.

172
00:09:13,530 --> 00:09:19,080
Side note I probably shouldn't have cut all my code and then have it in my copy buffer for quite so

173
00:09:19,080 --> 00:09:19,710
long.

174
00:09:19,740 --> 00:09:21,480
You only say coffee buffer for a second there.

175
00:09:21,480 --> 00:09:22,860
Some of us need that in the morning.

176
00:09:23,280 --> 00:09:25,170
Just a side note, I'm feeling a little bit foolish.

177
00:09:25,170 --> 00:09:28,560
I'm actually just going to paste it down here now so I don't accidentally lose it.

178
00:09:28,560 --> 00:09:31,800
That was a little bit crazy living on the edge what I was doing there.

179
00:09:31,800 --> 00:09:35,520
Now when we create a code routine, the first thing we need to do is be yielding.

180
00:09:35,760 --> 00:09:38,220
So yield, return, new.

181
00:09:38,220 --> 00:09:43,710
That's our way of saying, okay, we want to just hang out and chill for a second here and I'll use

182
00:09:43,710 --> 00:09:45,180
the terminology.

183
00:09:45,180 --> 00:09:47,280
Let's say we've got wait for end of frame.

184
00:09:47,280 --> 00:09:48,780
No, wait for fixed update.

185
00:09:48,780 --> 00:09:49,680
No, wait 4 seconds.

186
00:09:49,680 --> 00:09:54,270
We could do wait 4 seconds or wait 4 seconds real time, which I think is going to be more of an accurate

187
00:09:54,510 --> 00:10:00,090
actually, if I say it's 1/2, it's going to be 1/2 in row, and then how long?

188
00:10:00,090 --> 00:10:02,040
How many RL seconds do we want to wait?

189
00:10:02,040 --> 00:10:07,800
Well, I'll parameterized this as a variable, so we'll call it level load delay.

190
00:10:08,770 --> 00:10:13,630
And semicolon we'll go create that up at the top pump serialize field.

191
00:10:13,630 --> 00:10:20,920
It will be a float and called level load delay and we'll make that one as a starting point.

192
00:10:21,370 --> 00:10:27,160
Now, after we've done our weighting, the bit that I had in my coffee buffer, I can now paste.

193
00:10:27,340 --> 00:10:28,090
Oh, there we go.

194
00:10:28,090 --> 00:10:30,700
I've also pasted it down below, which I'll get rid of in a second.

195
00:10:30,700 --> 00:10:31,730
That was my back up.

196
00:10:31,750 --> 00:10:32,890
That was my just in case.

197
00:10:32,890 --> 00:10:35,830
That was a cup of tea in case there's no coffee available.

198
00:10:35,860 --> 00:10:37,060
Or delete that.

199
00:10:37,270 --> 00:10:37,960
Delete that.

200
00:10:37,960 --> 00:10:38,710
Delete that.

201
00:10:38,710 --> 00:10:40,230
And just tidy out the formatting.

202
00:10:40,240 --> 00:10:43,420
So now we're saying yield for a certain amount of seconds.

203
00:10:43,420 --> 00:10:48,130
We're saying one and then do these things, load our thingy and then we're all good.

204
00:10:48,130 --> 00:10:49,180
So let's see if that works.

205
00:10:49,180 --> 00:10:49,930
Save that up.

206
00:10:50,020 --> 00:10:58,450
Our goal here is to touch the exit sign and have 1/2 elapse before we load into the next scene and run.

207
00:10:58,450 --> 00:10:59,770
Jump one.

208
00:11:00,070 --> 00:11:00,470
No.

209
00:11:00,580 --> 00:11:01,100
There we go.

210
00:11:01,120 --> 00:11:01,770
Perfect.

211
00:11:01,780 --> 00:11:06,280
So the last step in here is for me to go and put my my level exit and all of my levels.

212
00:11:06,280 --> 00:11:07,570
So we'll just do a bit of saving.

213
00:11:07,570 --> 00:11:09,000
And level one, jump into level two.

214
00:11:09,010 --> 00:11:09,730
Where are you going to be?

215
00:11:09,730 --> 00:11:10,990
Down the bottom here.

216
00:11:11,020 --> 00:11:12,350
Did I prefab that?

217
00:11:12,370 --> 00:11:13,660
Did I prefab my level?

218
00:11:13,660 --> 00:11:15,730
And did I put all the stuff on it properly?

219
00:11:16,030 --> 00:11:16,470
I don't know.

220
00:11:16,480 --> 00:11:19,720
Don't pick up my habits at home, boys and girls.

221
00:11:19,720 --> 00:11:24,370
Let me just go back to my level, level, level one, find the exit.

222
00:11:24,370 --> 00:11:25,720
That's the instance in there.

223
00:11:25,720 --> 00:11:26,500
Overrides.

224
00:11:26,500 --> 00:11:27,160
There's no override.

225
00:11:27,170 --> 00:11:27,610
Okay, good.

226
00:11:27,610 --> 00:11:29,070
So everything was on the prefab.

227
00:11:29,080 --> 00:11:29,530
I did it.

228
00:11:29,530 --> 00:11:29,800
Okay.

229
00:11:29,800 --> 00:11:31,030
It didn't make any mistakes.

230
00:11:31,160 --> 00:11:31,600
Phew.

231
00:11:31,870 --> 00:11:32,260
Okay.

232
00:11:32,260 --> 00:11:36,850
Prefabs drag that into our world and then.

233
00:11:37,590 --> 00:11:40,050
Jump into the next level, level three and.

234
00:11:40,760 --> 00:11:43,130
Drag the exit in there once again.

235
00:11:44,320 --> 00:11:45,280
Right in that spot.

236
00:11:45,280 --> 00:11:46,460
It's a little bit big for there.

237
00:11:46,480 --> 00:11:52,840
So in this particular level, we can make the instance of the exit a little bit smaller, make it 0.3

238
00:11:52,840 --> 00:11:53,640
and 0.3.

239
00:11:53,650 --> 00:11:54,400
That fits.

240
00:11:55,840 --> 00:11:56,410
Just because.

241
00:11:56,440 --> 00:11:58,720
Or I could have dug out a little bit more space in there.

242
00:11:58,720 --> 00:11:59,740
Either way, it's all fine.

243
00:11:59,740 --> 00:12:01,750
It's just sort of finessing at this stage.

244
00:12:02,380 --> 00:12:07,150
It's a little bit more sneakily hidden in there, which is, okay, so let's grab our player and pop

245
00:12:07,150 --> 00:12:10,990
our player right next to this exit and see what happens when we touch that one.

246
00:12:10,990 --> 00:12:13,810
Because we know what happens when we go from 0 to 1, 1 to 2.

247
00:12:13,840 --> 00:12:15,310
We're currently in build index two.

248
00:12:15,340 --> 00:12:20,320
What happens when we touch that 1/2 and it says, Oh, I don't know where I should go to just here,

249
00:12:20,320 --> 00:12:22,750
it's going to give us an error or it's just not going to connect.

250
00:12:22,750 --> 00:12:25,600
It's giving us an error down here now saying, Oh, there is no next level.

251
00:12:25,600 --> 00:12:29,020
We're at the highest one we've found, so it's going to skip over that and not worry about it.

252
00:12:29,020 --> 00:12:30,700
But then I figured, Oh, that's kind of lazy.

253
00:12:30,700 --> 00:12:33,670
Let's put in a little bit of code to protect ourselves against that.

254
00:12:33,670 --> 00:12:41,470
Let's rearrange things here a little bit and say to ourselves, integer, let's say next scene index.

255
00:12:41,470 --> 00:12:47,170
So not currency in index, but next scene index is going to equal what we've got down here, a currency

256
00:12:47,170 --> 00:12:48,370
and an index plus one.

257
00:12:48,370 --> 00:12:51,280
So copy, pop that in there semicolon.

258
00:12:51,280 --> 00:12:58,930
So we need a way of comparing what is the next scene index with what how many scenes do we feel is in

259
00:12:58,930 --> 00:12:59,620
our level?

260
00:12:59,620 --> 00:13:03,070
So if the next one is three and there's a grand total of three, we're fine.

261
00:13:03,070 --> 00:13:06,490
If the next one is four, but we've only got three, then we've got an issue.

262
00:13:06,490 --> 00:13:13,120
So if next scene index, in other words, the level we're on at the moment plus one is equal, equal

263
00:13:13,120 --> 00:13:15,220
the same as scene manager.

264
00:13:15,220 --> 00:13:18,340
Once again, we're accessing our manager class within here.

265
00:13:18,370 --> 00:13:21,960
There's this cool property which has seen count in build settings.

266
00:13:21,970 --> 00:13:24,100
In other words, how many scenes are there?

267
00:13:24,100 --> 00:13:30,010
So we're comparing these to if the next one is the same as the total, then first of all, what we need

268
00:13:30,010 --> 00:13:36,310
to do in our curlies here is to assign or reset our next scene index to be zero.

269
00:13:36,310 --> 00:13:41,050
So we're saying, okay, if you've reached the end, then the next one is actually zero, reset it back

270
00:13:41,050 --> 00:13:41,590
to zero.

271
00:13:41,590 --> 00:13:49,780
And from there we can say see manager load scene and just straight up next scene index.

272
00:13:50,230 --> 00:13:51,370
Okay, hopefully that makes sense.

273
00:13:51,370 --> 00:13:52,750
I'll go through it just one more time.

274
00:13:52,750 --> 00:13:56,230
Really quickly in here we need the concept of saying what's coming up next?

275
00:13:56,230 --> 00:13:57,700
What's the next scene we're going to load?

276
00:13:57,700 --> 00:14:01,270
On the next level we're going to load and that's our current plus one.

277
00:14:01,270 --> 00:14:03,880
So from build index zero, the next one is going to be one.

278
00:14:03,880 --> 00:14:06,760
If we're on build index one, the next one is going to be two and so on.

279
00:14:06,760 --> 00:14:11,740
And if we get to the point where the next scene index so in other words, we're currently on two and

280
00:14:11,740 --> 00:14:14,020
we add one to it, that would make it three.

281
00:14:14,020 --> 00:14:20,230
If that is the same as the total number of scenes that we have in our game and we have three, then

282
00:14:20,230 --> 00:14:22,870
we need to reset our next scene, index back to zero.

283
00:14:22,870 --> 00:14:27,880
And then what we want to do is load whatever the next scene index is, which in this case is going to

284
00:14:27,880 --> 00:14:28,450
be zero.

285
00:14:28,480 --> 00:14:30,430
Let's save and see if that works.

286
00:14:30,430 --> 00:14:34,000
The goal here is so that when we're on our very last level, we'll load back to the start.

287
00:14:34,000 --> 00:14:38,710
No matter whether you have two or three or ten levels, this should still work for you.

288
00:14:41,470 --> 00:14:43,290
1/2 delay and back to the start.

289
00:14:43,300 --> 00:14:43,900
Awesome.

290
00:14:43,900 --> 00:14:46,510
And we'll just check that this first one works as well so that we go.

291
00:14:46,510 --> 00:14:47,340
All done.

292
00:14:47,350 --> 00:14:49,120
I hope that's working for you nicely.

293
00:14:49,120 --> 00:14:50,500
I will see you in the next lecture.

