1
00:00:03,020 --> 00:00:06,860
In this lecture, we're going to hook up in the code so that when Barry crashes or crosses the finish

2
00:00:06,860 --> 00:00:08,370
line, we trigger a boom.

3
00:00:08,390 --> 00:00:09,580
Our particle effects.

4
00:00:09,590 --> 00:00:11,410
The first thing to do is open up.

5
00:00:11,420 --> 00:00:11,780
Hmm.

6
00:00:11,810 --> 00:00:12,200
Let's see.

7
00:00:12,200 --> 00:00:16,610
We'll work on finish line together, and then I'll set you the challenge of working on the crash detector

8
00:00:16,610 --> 00:00:17,150
yourself.

9
00:00:17,150 --> 00:00:18,860
So we have finish line open.

10
00:00:18,860 --> 00:00:23,000
What we need to do, first of all, is create a reference for the particle system.

11
00:00:23,000 --> 00:00:24,080
So what do I mean by that?

12
00:00:24,080 --> 00:00:29,600
Well, when we tell unity to, hey, you bumped your head, play this particular thing, it's going

13
00:00:29,600 --> 00:00:33,050
to say to us, okay, Rick, what particular thing do you want me to play?

14
00:00:33,050 --> 00:00:37,580
So in this case, what I'm going to set up the reference is by jumping into my finish line script and

15
00:00:37,580 --> 00:00:44,510
saying or typing serialised field and I'm going to create a reference to a particle system and that

16
00:00:44,510 --> 00:00:50,150
particle system I am going to call finish effect semicolon.

17
00:00:50,150 --> 00:00:57,200
And so if we save this, when we jump back into unity, we find where our finishing line script is.

18
00:00:57,200 --> 00:00:59,660
It's on our finish line game object.

19
00:00:59,660 --> 00:01:02,780
Now you can see we have this finish effect option.

20
00:01:02,780 --> 00:01:07,640
So I'm going to grab the finish effect particle effect, drag that into my finish effect.

21
00:01:07,640 --> 00:01:09,470
Now back over into our script.

22
00:01:09,470 --> 00:01:14,660
Now that it's knows this finish effect, that's the variable that's storing our particle system, we

23
00:01:14,660 --> 00:01:16,600
can trigger it at the right point.

24
00:01:16,610 --> 00:01:18,650
The way we do that is on trigger enter.

25
00:01:18,650 --> 00:01:18,860
Yep.

26
00:01:18,860 --> 00:01:21,890
When we bump into something or when something bumps into us.

27
00:01:21,890 --> 00:01:26,240
Sorry if it's the player we want to invoke our load seen with our bit of a delay.

28
00:01:26,240 --> 00:01:29,330
And that's simply a case of accessing our particle effect.

29
00:01:29,330 --> 00:01:34,220
So finish effect which we know is a particle system dot and then we've got a few options in here.

30
00:01:34,220 --> 00:01:40,820
If you scroll through, you'll see one that is pretty aptly name, which is just play and then parentheses

31
00:01:40,820 --> 00:01:42,650
because it's a method and semicolon.

32
00:01:42,650 --> 00:01:47,510
It's as simple as that saying, Hey, play this particle effect, let's save that up and see if we have

33
00:01:47,510 --> 00:01:51,110
any unexpected consequences of doing this.

34
00:01:51,110 --> 00:01:54,770
I can think of one we might have now when I click on play.

35
00:01:54,860 --> 00:01:56,570
Does anything happen at the start?

36
00:01:57,230 --> 00:01:57,700
Yeah.

37
00:01:57,740 --> 00:01:58,070
Boom.

38
00:01:58,070 --> 00:02:00,760
We had a finish line effect before we even got there.

39
00:02:00,770 --> 00:02:01,220
That's cool.

40
00:02:01,220 --> 00:02:02,170
I'm glad that happened.

41
00:02:02,180 --> 00:02:07,460
When we click on Finish Effect, you can see there's a setting down here which is play on Awake.

42
00:02:07,460 --> 00:02:08,930
We want to uncheck that.

43
00:02:08,930 --> 00:02:12,950
If we have play on Awake, then literally when we click the play button, it will say, Oh, I'm ready

44
00:02:12,950 --> 00:02:14,720
to go and it'll play the particle system.

45
00:02:14,720 --> 00:02:15,950
We don't want to do that.

46
00:02:15,950 --> 00:02:20,540
So now when I click on play, let's see if this is going to work for us.

47
00:02:21,020 --> 00:02:23,240
That didn't zoom, zoom, zoom.

48
00:02:23,240 --> 00:02:25,850
And then as we cross the finish line, kaboom.

49
00:02:25,850 --> 00:02:31,790
Okay, it's playing it in the scene view, but it's not playing it in the game view.

50
00:02:31,790 --> 00:02:33,260
Why is that?

51
00:02:33,530 --> 00:02:41,120
Well, my guess is if we click on the finish effect, scroll all the way down, find our order in layer,

52
00:02:41,120 --> 00:02:45,470
set that to 100 just to make sure that's not going to be a thing at all.

53
00:02:45,470 --> 00:02:48,460
Okay, so let's scroll.

54
00:02:48,480 --> 00:02:50,960
You see the play on effect for that other particle effect.

55
00:02:50,960 --> 00:02:54,680
Kaboom in the world is playing in our scene view, but not our world view.

56
00:02:54,710 --> 00:02:55,580
It's a bit weird.

57
00:02:55,580 --> 00:02:56,630
Has got me a little bit confused.

58
00:02:56,630 --> 00:02:58,040
Let's see if we can figure this out.

59
00:02:58,040 --> 00:02:59,690
Okay, so I've had a little bit of a poke around.

60
00:02:59,690 --> 00:03:00,950
I think I know what the issue here is.

61
00:03:00,950 --> 00:03:06,230
We click on the 2D button or click to change from 2D to 3D.

62
00:03:06,230 --> 00:03:09,260
You can see that our particle effect is I don't even know where that is.

63
00:03:09,260 --> 00:03:14,180
You know, it's behind the camera so we can see it when we're in scene view, but we can't see it when

64
00:03:14,180 --> 00:03:14,930
we're in game view.

65
00:03:14,930 --> 00:03:22,430
So the reason that's happening is our finish line has let's see the finish line, Z position or Z position

66
00:03:22,430 --> 00:03:26,690
is at -35 and our particle effect is at zero.

67
00:03:26,690 --> 00:03:28,400
So the particle effect is right on top.

68
00:03:28,400 --> 00:03:29,720
There's some weirdness going on there.

69
00:03:29,720 --> 00:03:30,800
So let's just sort that out.

70
00:03:30,800 --> 00:03:32,210
Let's go to the finishing line.

71
00:03:32,210 --> 00:03:34,970
Let's make this zero for the Z value.

72
00:03:34,970 --> 00:03:38,030
And then you can see that the post is way off in the background.

73
00:03:38,030 --> 00:03:39,500
I think those ones are.

74
00:03:39,500 --> 00:03:40,460
So my apologies.

75
00:03:40,460 --> 00:03:42,710
I didn't zero those out when we created those.

76
00:03:42,710 --> 00:03:48,140
So you click on post, make the z value zero, click on top, make that zero as well.

77
00:03:48,140 --> 00:03:49,640
Let's click on the finish effect.

78
00:03:49,640 --> 00:03:51,200
It's at zero, the finish line.

79
00:03:51,200 --> 00:03:52,190
So it's all at zero.

80
00:03:52,190 --> 00:03:55,520
Nothing is being way off in the distance or the other side of the camera.

81
00:03:55,520 --> 00:03:58,790
Now when we click on play, we should see that.

82
00:03:59,120 --> 00:04:01,820
But we cruise along kind of.

83
00:04:01,820 --> 00:04:03,320
We'd looking at it over that other side.

84
00:04:03,320 --> 00:04:04,250
Yes, it's in front.

85
00:04:04,250 --> 00:04:05,480
Boom, and then we reload.

86
00:04:05,480 --> 00:04:05,840
Excellent.

87
00:04:05,840 --> 00:04:06,350
So there we go.

88
00:04:06,350 --> 00:04:07,790
We've got that figured out.

89
00:04:07,790 --> 00:04:08,660
Job well done.

90
00:04:08,660 --> 00:04:11,330
Click back on 2D to go back into 2D mode.

91
00:04:11,420 --> 00:04:14,990
I'm going to save that up and I'm going to issue you a challenge.

92
00:04:15,440 --> 00:04:20,420
The challenge is to trigger our crash particles so when the player crashes, trigger the crash particles

93
00:04:20,420 --> 00:04:26,300
to play and make sure you pay attention to things like the order to sort all that out, as well as making

94
00:04:26,300 --> 00:04:29,810
sure that there's no weirdness like play on Awake, for example.

95
00:04:29,810 --> 00:04:30,920
So that's a challenge.

96
00:04:30,920 --> 00:04:31,430
Take that on.

97
00:04:31,430 --> 00:04:32,510
So you back here when you're done.

98
00:04:35,530 --> 00:04:36,220
Okey dokey.

99
00:04:36,220 --> 00:04:40,540
So the first thing I'm going to do because I noticed it before was click on Barre, click on the crash

100
00:04:40,540 --> 00:04:41,050
effect.

101
00:04:41,050 --> 00:04:43,870
And as soon as I click on it, we get this play on a wake.

102
00:04:43,870 --> 00:04:45,730
So I'm going to turn off play on a wake bump.

103
00:04:45,730 --> 00:04:48,250
So not playing when we are awaking.

104
00:04:48,250 --> 00:04:56,380
Now I'm going to jump into my crash detector script and once again I'm going to serialize a variable

105
00:04:56,380 --> 00:04:57,460
serialize field.

106
00:04:57,460 --> 00:05:04,480
And this will be once again particle system and we will call this crash effect semicolon.

107
00:05:04,480 --> 00:05:05,770
Now, where are we going to play this?

108
00:05:05,770 --> 00:05:08,020
Well, we're going to play it when we bump into something.

109
00:05:08,020 --> 00:05:10,930
You could do this before your invoke or after your invoke.

110
00:05:10,930 --> 00:05:11,980
It doesn't matter so much.

111
00:05:11,980 --> 00:05:16,300
But you do want to ask yourself, is there going to be a difference if I do a thing before an other

112
00:05:16,300 --> 00:05:16,930
thing?

113
00:05:16,930 --> 00:05:20,470
In this case, playing the particle system, I think is a good thing to come first.

114
00:05:20,470 --> 00:05:25,150
Before we say, now, I'd like you to load the scene, but it shouldn't make a big impact, but we'll

115
00:05:25,150 --> 00:05:26,200
pop it first nonetheless.

116
00:05:26,200 --> 00:05:33,580
So we're going to say crash effect, dot, play, parentheses, semicolon and save jump back to unity.

117
00:05:33,610 --> 00:05:34,900
Let's just have a look at our order.

118
00:05:34,900 --> 00:05:39,280
So Barry's on zero border, top and bottom run zero, crash effect zero.

119
00:05:39,280 --> 00:05:40,450
So that should all be fine.

120
00:05:40,450 --> 00:05:41,290
Good stuff.

121
00:05:41,590 --> 00:05:43,210
Let's do a dump.

122
00:05:43,210 --> 00:05:45,880
Dump, and then we'll just spin backwards and crash.

123
00:05:45,880 --> 00:05:46,720
Nothing happened.

124
00:05:46,720 --> 00:05:48,250
Okay, the crash variable.

125
00:05:48,340 --> 00:05:49,600
Okay, this is cool.

126
00:05:49,600 --> 00:05:54,970
So we've seen an exception and we haven't talked about this a lot, but this is something you might

127
00:05:54,970 --> 00:05:56,440
be seeing in your code from time to time.

128
00:05:56,440 --> 00:05:59,290
Down the bottom you see our little red thing pop up.

129
00:05:59,290 --> 00:06:03,700
So we go to the console that will give us more information as saying the variable crash effect of crash

130
00:06:03,700 --> 00:06:10,330
detector is not been a That's because Rick forgot to go back over into the Barry script, the crash

131
00:06:10,330 --> 00:06:12,430
detector script, see how we've got crash effect.

132
00:06:12,430 --> 00:06:18,520
I need a drag crash effect right onto there to say this is now referencing that I made such a big deal

133
00:06:18,520 --> 00:06:22,420
about references before than I went and forgot to reference this.

134
00:06:22,450 --> 00:06:26,320
Now when we click on play it actually knows what to trigger when we crash.

135
00:06:26,320 --> 00:06:27,550
So crash bump.

136
00:06:27,550 --> 00:06:28,150
There we go.

137
00:06:28,150 --> 00:06:32,110
Okay, one thing you'll notice as we move, the particle effect is moving with us.

138
00:06:32,110 --> 00:06:32,770
Do we want that?

139
00:06:32,770 --> 00:06:38,110
Do we want the the crunch to be following or staying in the world?

140
00:06:38,110 --> 00:06:40,480
I think I want to try having it stay in the world.

141
00:06:40,480 --> 00:06:46,480
So if I crash just here, then the crash particle stages there rather than flowing along with me.

142
00:06:46,480 --> 00:06:47,290
So we'll just try that.

143
00:06:47,290 --> 00:06:48,070
We'll see what works better.

144
00:06:48,070 --> 00:06:52,780
If you click on Crash Effect, there's a setting in here which is simulation space.

145
00:06:52,780 --> 00:06:58,300
You see it right near the top or right near the top of all of our modules, simulation space, change

146
00:06:58,300 --> 00:07:02,890
that from local to world, which means that the particle effects will stay wherever they are in the

147
00:07:02,890 --> 00:07:03,400
world.

148
00:07:03,400 --> 00:07:07,960
They won't continue to travel along locally, in other words, locally with Barry.

149
00:07:07,960 --> 00:07:10,420
So let's see if that look is any different.

150
00:07:10,420 --> 00:07:12,100
Kind of might be the same, to be honest.

151
00:07:12,100 --> 00:07:16,840
So we'll go crash kind of stays in the world and but for now I think that's fine.

152
00:07:16,840 --> 00:07:21,250
Okay so we're now triggering our particle effects when we go through the finish line and when we go

153
00:07:21,250 --> 00:07:21,580
bump.

154
00:07:21,580 --> 00:07:25,960
And you've learned how to use the play method when it comes to particle systems.

155
00:07:25,960 --> 00:07:26,320
Okay.

156
00:07:26,320 --> 00:07:27,430
I'll see you in the next lecture.

