1
00:00:03,090 --> 00:00:06,510
Next up, we're going to create ourselves a win condition and a lose condition.

2
00:00:06,510 --> 00:00:08,070
What do we mean by win condition?

3
00:00:08,070 --> 00:00:09,270
Well, how do we win this level?

4
00:00:09,270 --> 00:00:10,890
What's the criteria for winning?

5
00:00:10,890 --> 00:00:15,000
And for me, it's going to be get all the way to the end and you cross the checkpoint without crashing,

6
00:00:15,000 --> 00:00:15,900
then you win.

7
00:00:15,900 --> 00:00:19,920
And for our simple little game we're making, when your win will just restart you back to the start

8
00:00:19,920 --> 00:00:20,610
of the level.

9
00:00:20,610 --> 00:00:22,350
Likewise, I need a lose condition.

10
00:00:22,350 --> 00:00:26,850
So the lose condition will be if I'm cruising along and I bump my head, then I lose.

11
00:00:26,850 --> 00:00:30,150
And as with winning, we're going to restart the scene.

12
00:00:30,150 --> 00:00:35,370
So in this lecture what we'll do is hook up the functionality to detect when we've won or when we've

13
00:00:35,370 --> 00:00:35,670
lost.

14
00:00:35,670 --> 00:00:40,200
And in the next lecture we'll hook up the functionality to reload our scene.

15
00:00:40,200 --> 00:00:45,240
So I'm going to start with a win condition, and I should put my win condition all the way down the

16
00:00:45,240 --> 00:00:46,950
very end, all the way down there.

17
00:00:46,950 --> 00:00:48,780
But you're not for testing purposes.

18
00:00:48,780 --> 00:00:52,800
I'm going to put my win condition right here, right next to the player, just so we don't have to skate

19
00:00:52,800 --> 00:00:54,750
along for so long before we test it out.

20
00:00:54,750 --> 00:00:56,880
I'm going to create two new scripts down here.

21
00:00:56,880 --> 00:00:59,010
So right click Create C-sharp script.

22
00:00:59,010 --> 00:01:05,040
The first one I will call Finish Line and the second one I will call.

23
00:01:05,040 --> 00:01:07,620
So right click Create C-sharp script.

24
00:01:07,740 --> 00:01:16,200
I'll call this crash the tech door and I'm going to work on the finish line first and then I'll challenge

25
00:01:16,200 --> 00:01:17,760
you to work on the crash detector.

26
00:01:17,760 --> 00:01:18,540
How does that sound?

27
00:01:18,540 --> 00:01:19,170
A pretty good plan.

28
00:01:19,170 --> 00:01:23,550
I reckon it's going to right click in the hierarchy and I'm going to create an empty game object.

29
00:01:23,550 --> 00:01:28,680
And the reason I'm creating an empty is I want some visual representation on this, but I don't want

30
00:01:28,680 --> 00:01:33,090
the visual representation to change if I'm manipulating the parent.

31
00:01:33,090 --> 00:01:37,290
So I'm going to have the visual representation underneath the game object.

32
00:01:37,290 --> 00:01:40,800
So we'll call the game object finish line like that.

33
00:01:40,800 --> 00:01:42,480
And then the visual representation.

34
00:01:42,480 --> 00:01:48,060
I'm going to right click on finish line and create a 2D object sprites and a square.

35
00:01:48,060 --> 00:01:49,200
I think square is fine.

36
00:01:49,200 --> 00:01:54,540
Now the square you can see has come in zeroed in at the zero of our finish line.

37
00:01:54,540 --> 00:02:01,080
So it's right in the zero point of finish line child relative to parent and we'll call this post and

38
00:02:01,080 --> 00:02:02,610
I'm going to just manipulate a little bit.

39
00:02:02,610 --> 00:02:05,880
So hit R to scale in and to scale up.

40
00:02:05,880 --> 00:02:08,100
We want a nice big old post looking thing.

41
00:02:08,110 --> 00:02:11,160
I'm going to change the color to red, I think.

42
00:02:11,160 --> 00:02:12,330
So it pops out from the snow.

43
00:02:12,360 --> 00:02:13,470
That seems pretty good.

44
00:02:13,470 --> 00:02:17,730
And now click on finish line, right click and create a 2D object.

45
00:02:17,730 --> 00:02:19,680
This will be a circle.

46
00:02:19,680 --> 00:02:24,690
Now the circle I'm going to rename to be the top, I guess, and we'll just kind of have this as the

47
00:02:24,690 --> 00:02:26,820
top that goes on top of the post.

48
00:02:26,820 --> 00:02:29,100
And once again, I'll, I'll make this red.

49
00:02:29,100 --> 00:02:33,090
Now if you wanted to make it the exact same color red, I can click on the post, click on the color

50
00:02:33,090 --> 00:02:40,320
picker, find the hexadecimal which is F 10,000 and then click on top, click on the color and paste

51
00:02:40,320 --> 00:02:40,800
that in there.

52
00:02:40,800 --> 00:02:41,100
Boink.

53
00:02:41,130 --> 00:02:41,640
There we go.

54
00:02:41,640 --> 00:02:43,680
Now it's exactly the same color.

55
00:02:43,680 --> 00:02:48,090
If I click on the parent of the finish line now, I can move this around and kind of anchor it into

56
00:02:48,090 --> 00:02:49,020
the snow like that.

57
00:02:49,020 --> 00:02:53,880
Now the next step is that I need to put some collusion on this thing so that when the player goes flying

58
00:02:53,880 --> 00:02:56,340
through it, we know that we've actually collided with it.

59
00:02:56,340 --> 00:02:58,500
So I'm going to click on my finish line.

60
00:02:58,500 --> 00:03:02,340
Parent level ad component will make a collider.

61
00:03:02,340 --> 00:03:04,080
What sort do we want a box collider to?

62
00:03:04,080 --> 00:03:06,060
DX You can see it's a little bit smaller here.

63
00:03:06,060 --> 00:03:07,710
The player could accidentally jump over that.

64
00:03:07,710 --> 00:03:11,130
So what I'm going to do under size and offset, I'm going to manipulate this.

65
00:03:11,130 --> 00:03:16,860
So size will make it, let's see, nice and high, probably gigantic on the Y.

66
00:03:16,860 --> 00:03:19,770
So there's no way of me being able to kind of fly over it.

67
00:03:19,770 --> 00:03:22,920
So we've got this nice big old collision that we're going to bump into.

68
00:03:22,920 --> 00:03:26,820
We're going to make it a trigger because if we didn't make it a trigger, we'd go clunk and clunk into

69
00:03:26,820 --> 00:03:28,050
this invisible force field.

70
00:03:28,050 --> 00:03:29,310
So we need to make this a trigger.

71
00:03:29,310 --> 00:03:32,910
So it's got a trigger box and it's got some visual representation to it.

72
00:03:32,910 --> 00:03:36,540
Now, the last thing for the finish line while we're in here in Unity is grab the finish line script

73
00:03:36,540 --> 00:03:39,210
and drag that over onto finish line.

74
00:03:39,210 --> 00:03:43,680
So the player is responsible for what it's doing, but it's the finishing line that's responsible for

75
00:03:43,680 --> 00:03:46,410
saying what happens when something goes through the finish line.

76
00:03:46,410 --> 00:03:48,990
That's why we're putting our code on the finish line.

77
00:03:48,990 --> 00:03:53,070
But sometimes when you're going through this process, you'll think, Hmm, should I put it on this

78
00:03:53,070 --> 00:03:54,930
game object or on that game object?

79
00:03:54,930 --> 00:04:00,060
And there's many ways to go about doing it, but I like to put the logic on the thing that is doing

80
00:04:00,060 --> 00:04:04,500
the controlling or or has the power in this case and the finish line has the power.

81
00:04:04,740 --> 00:04:08,010
Let's open up our finish line script and we've done this before.

82
00:04:08,010 --> 00:04:10,020
We're going to do an on collision enter.

83
00:04:10,020 --> 00:04:16,230
So get rid of my start and update methods and on sorry, not on collision enter on trigger enter.

84
00:04:16,230 --> 00:04:17,610
They're quite similar aren't they.

85
00:04:17,610 --> 00:04:18,990
On trigger enter.

86
00:04:18,990 --> 00:04:23,010
I'm going to remove private and reformat a tiny bit because I like to do that.

87
00:04:23,010 --> 00:04:24,360
Now, what's going on in here?

88
00:04:24,360 --> 00:04:29,160
Well, for now all we going to do is just debug log, which is going to print out something to the console,

89
00:04:29,160 --> 00:04:36,660
parentheses, semicolon quotation marks and I'm going to print you finished as simple as that.

90
00:04:36,660 --> 00:04:39,330
And then semicolon down the end.

91
00:04:39,330 --> 00:04:42,720
Save that up, jump back over into unity.

92
00:04:42,720 --> 00:04:45,720
Click on the console so I can see this message.

93
00:04:47,020 --> 00:04:48,730
Book, click on play.

94
00:04:49,690 --> 00:04:50,250
Here we go.

95
00:04:50,260 --> 00:04:51,300
Slice, I say plump.

96
00:04:51,310 --> 00:04:51,970
You finished?

97
00:04:51,970 --> 00:04:53,680
We've got a couple of you finishes in there.

98
00:04:53,680 --> 00:04:54,400
That's all good.

99
00:04:54,400 --> 00:04:58,300
That's probably representing the fact that I've got a two colliders on here.

100
00:04:58,300 --> 00:05:01,560
So each time these colliders have gone through, it's like you finish and then you finish.

101
00:05:01,570 --> 00:05:02,290
That's cool.

102
00:05:02,380 --> 00:05:03,310
It doesn't matter for us.

103
00:05:03,310 --> 00:05:06,760
Now, which point of this is probably the snowboard is fine going through.

104
00:05:06,760 --> 00:05:10,810
It doesn't really matter if there's two things, because once we go through, then we want a particular

105
00:05:10,810 --> 00:05:11,560
thing to happen.

106
00:05:11,560 --> 00:05:13,690
So we might change that later on, but it's cool for now.

107
00:05:13,690 --> 00:05:16,780
I think that's why we've got our two u finished on there.

108
00:05:16,840 --> 00:05:18,400
So that is success.

109
00:05:18,400 --> 00:05:23,140
From that point of view, what we should probably do is just make sure nothing else can go through this.

110
00:05:23,140 --> 00:05:27,490
We might have some creatures or some other objects, and you want to make sure in general that if it's

111
00:05:27,490 --> 00:05:32,470
only the player that can trigger something, then you protect for that and you make sure only the player

112
00:05:32,470 --> 00:05:33,220
can impact that.

113
00:05:33,220 --> 00:05:38,710
So what we need to do in here is just make sure that we're saying if it's the player that slides through

114
00:05:38,710 --> 00:05:40,690
here, then go about doing this thing.

115
00:05:40,690 --> 00:05:42,220
So how do we know it's the player?

116
00:05:42,220 --> 00:05:44,950
Well, if I click on Barre, we did a little bit of this in the previous section.

117
00:05:44,950 --> 00:05:47,380
We got up to Untagged where it says Tag here.

118
00:05:47,380 --> 00:05:52,240
Untagged, which has yet to play a player, is one of the tags that unity comes with already.

119
00:05:52,240 --> 00:05:55,840
So now Unity knows you are the player, you're tagged as the player.

120
00:05:55,870 --> 00:05:57,160
Jump back over into here.

121
00:05:57,160 --> 00:05:59,950
We just want to make sure that we're only printing this if it's the player.

122
00:05:59,950 --> 00:06:04,090
So if and we can get information from other.

123
00:06:04,090 --> 00:06:09,730
So when we have this trigger event, we get information about the collider, about the thing that collided

124
00:06:09,730 --> 00:06:11,830
with us and it's named as other.

125
00:06:11,830 --> 00:06:18,280
So if other so the thing that collided with this dot tag equals equals and we use the equals equals

126
00:06:18,310 --> 00:06:23,020
operator equals operator because we're saying if it is this particular thing, if there was only one

127
00:06:23,020 --> 00:06:26,680
equals, then we'd be saying, hey, we want to make the thing on the left equal to the thing on the

128
00:06:26,680 --> 00:06:26,950
right.

129
00:06:26,950 --> 00:06:32,140
But we're saying if it equals this particular thing and what is it in our quotation marks, we're looking

130
00:06:32,140 --> 00:06:34,390
for a player with a capital P that's important.

131
00:06:34,390 --> 00:06:39,670
Then we're going to wrap in our curly braces debug log.

132
00:06:40,150 --> 00:06:41,290
You finished?

133
00:06:41,290 --> 00:06:41,980
We'll save that.

134
00:06:41,980 --> 00:06:44,200
We'll make sure that that particular thing works.

135
00:06:44,200 --> 00:06:46,600
Clear my console, click on play.

136
00:06:47,440 --> 00:06:47,890
Here we go.

137
00:06:47,920 --> 00:06:48,550
Slide slides.

138
00:06:48,550 --> 00:06:49,090
Slide.

139
00:06:49,120 --> 00:06:49,870
Any second now.

140
00:06:49,870 --> 00:06:50,530
Slides I slide.

141
00:06:50,530 --> 00:06:50,890
Bump.

142
00:06:50,890 --> 00:06:51,850
We get you finished.

143
00:06:51,850 --> 00:06:52,450
Wonderful.

144
00:06:52,450 --> 00:06:56,470
Okay, so we've completed that stage of knowing when the player slides through.

145
00:06:56,470 --> 00:06:56,760
So.

146
00:06:56,800 --> 00:07:01,870
Okay, so now that we've done that, I want to do the same thing, but for when the play is head.

147
00:07:01,870 --> 00:07:05,950
So this trigger volume just here bumps into the ground.

148
00:07:05,950 --> 00:07:11,560
When that happens, I want to have our level reset, but for now, we're just going to print out something

149
00:07:11,560 --> 00:07:15,940
in the screen that says you bonked your head, so I'm going to give this to you as a challenge that's

150
00:07:15,940 --> 00:07:17,530
to finish the crash detector.

151
00:07:17,530 --> 00:07:22,780
So in our crash detector script, write some code that will print to the screen if we bonk our head

152
00:07:22,780 --> 00:07:24,250
on the ground.

153
00:07:24,250 --> 00:07:25,180
There's your challenge.

154
00:07:25,180 --> 00:07:25,840
Take that on.

155
00:07:25,840 --> 00:07:27,010
See you back here when you're done.

156
00:07:29,770 --> 00:07:30,250
Okay.

157
00:07:30,250 --> 00:07:33,640
So let's find our project crash detector.

158
00:07:33,670 --> 00:07:34,630
Open that up.

159
00:07:34,630 --> 00:07:41,590
And in here, we're going to do similar sort of logic before we're going to have a on trigger enter

160
00:07:41,590 --> 00:07:44,770
to de tidy it up a little bit.

161
00:07:45,190 --> 00:07:49,420
And for this I think I'm going to have the player responsible for this.

162
00:07:49,420 --> 00:07:52,840
So the player needs to know I crashed, I need to do a thing.

163
00:07:52,840 --> 00:07:55,120
So it's all about I crashed into a particular thing.

164
00:07:55,120 --> 00:07:59,620
Whereas the finishing line I was saying, Hey, someone pass through the finish line, do a particular

165
00:07:59,620 --> 00:07:59,920
thing.

166
00:07:59,920 --> 00:08:03,640
So like I said before, there's a little bit of you can do it one way or do it the other, but I feel

167
00:08:03,640 --> 00:08:07,090
good putting the crash detection as a script that lives on the player.

168
00:08:07,090 --> 00:08:07,930
So I'll do that right now.

169
00:08:07,930 --> 00:08:11,800
Click on barrier, just drag crash detector over there.

170
00:08:11,800 --> 00:08:13,510
Just had to scroll down the bottom so I can see it.

171
00:08:13,510 --> 00:08:14,140
There we go.

172
00:08:14,170 --> 00:08:19,120
Just going to roll up my circle collider and my rigid body so I can see these things a bit more clearly.

173
00:08:19,120 --> 00:08:22,150
So now it's the player saying, I bumped into something.

174
00:08:22,150 --> 00:08:23,260
What are we going to bump into?

175
00:08:23,260 --> 00:08:28,630
Well, if I click on the ground, the level sprite shape it's currently untagged, I might actually

176
00:08:28,630 --> 00:08:29,980
tag this as ground.

177
00:08:29,980 --> 00:08:32,650
So you didn't have to do this, have to have to do this.

178
00:08:32,650 --> 00:08:35,740
But I think this is a good layer of thoroughness.

179
00:08:35,740 --> 00:08:40,720
We're going to add tag whatever you want, but I'm going to click on the plus button and coal mine,

180
00:08:40,720 --> 00:08:46,390
Ground Save, click on the ground itself again and then just tag it as ground.

181
00:08:46,390 --> 00:08:49,030
So it's similar to what we were doing before we tag the player as player.

182
00:08:49,060 --> 00:08:50,740
We're tagging the ground as ground.

183
00:08:50,740 --> 00:08:54,040
So when the player bumps into the ground, we can do a particular thing.

184
00:08:54,040 --> 00:08:58,150
So back to a script over here, back to our script over here, our crash detector.

185
00:08:58,150 --> 00:09:05,260
I'm going to say if the other tag equals equals what it equals ground, then we're going to do a thing.

186
00:09:05,260 --> 00:09:08,650
And for now it is going to debug dot log.

187
00:09:09,010 --> 00:09:09,820
Ouch.

188
00:09:09,820 --> 00:09:13,810
Hit my head semicolon.

189
00:09:13,810 --> 00:09:17,080
Feel free to insert your own witty clever comment in there.

190
00:09:17,080 --> 00:09:23,950
You don't have to use my semi witty semi clever comment will save that up and then jump back over into

191
00:09:23,950 --> 00:09:28,780
unity and once again click on the console, clear the message, click on play.

192
00:09:28,780 --> 00:09:31,990
I'm going to see if I can rotate straight away and flip upside down.

193
00:09:33,780 --> 00:09:34,230
No, no.

194
00:09:34,300 --> 00:09:35,380
I was clicked in the wrong window.

195
00:09:35,380 --> 00:09:37,330
You can't control if you clicked in the scene window.

196
00:09:37,330 --> 00:09:40,810
So I'm going to move my window over here game window and do a rotate.

197
00:09:40,810 --> 00:09:41,740
And then here we go.

198
00:09:41,740 --> 00:09:43,570
Bump your head, boink out.

199
00:09:43,570 --> 00:09:44,140
Hit my head.

200
00:09:44,140 --> 00:09:44,830
Bump, bump, bump.

201
00:09:44,830 --> 00:09:45,530
Wonderful.

202
00:09:45,660 --> 00:09:46,510
Okay, so out.

203
00:09:46,510 --> 00:09:47,170
Hit my head.

204
00:09:47,170 --> 00:09:51,070
And when we go through the finishing line, it's saying you got through the finishing line.

205
00:09:51,070 --> 00:09:55,690
So there's the mechanics of our reloading on our win event and our lose event.

206
00:09:55,690 --> 00:10:00,520
In the next lecture, we will set ourselves up where it actually will reload our particular scene.

207
00:10:00,520 --> 00:10:01,840
Okay, so in the next lecture.

