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

2
00:00:03,435 --> 00:00:07,775
In this video, we've added a Trail Renderer to our bullet.

3
00:00:07,770 --> 00:00:10,590
I'm going to make it a bit exaggerated so you can

4
00:00:10,590 --> 00:00:13,970
see clearly what's happening when we run our game.

5
00:00:13,965 --> 00:00:16,415
When we shoot our bullet.

6
00:00:16,410 --> 00:00:17,100
There you go.

7
00:00:17,100 --> 00:00:20,720
You can see that it has some kind of trailed behind it.

8
00:00:20,715 --> 00:00:22,755
I'm going to make it a bit bigger.

9
00:00:22,755 --> 00:00:25,065
So you clearly see what's going on.

10
00:00:25,065 --> 00:00:26,245
I shoot a bullet.

11
00:00:26,245 --> 00:00:27,445
Well, there you go.

12
00:00:27,440 --> 00:00:30,200
You can see our cool looking trail,

13
00:00:30,200 --> 00:00:32,090
the trails behind the bullet.

14
00:00:32,090 --> 00:00:33,650
Actually it's not perfect.

15
00:00:33,650 --> 00:00:35,030
It's not that nice.

16
00:00:35,030 --> 00:00:40,600
But I left the creativity part to you because while I know myself,

17
00:00:40,595 --> 00:00:42,785
I'm not that creative with that said,

18
00:00:42,785 --> 00:00:44,185
let's not waste any more time.

19
00:00:44,180 --> 00:00:46,820
We fix a small problem that we had,

20
00:00:46,820 --> 00:00:49,070
but we didn't see before maybe you've

21
00:00:49,070 --> 00:00:52,340
noticed it and thought moon, Michael forgot something.

22
00:00:52,340 --> 00:00:54,200
What is E such a burden structs you.

23
00:00:54,200 --> 00:00:58,670
No, no, I'm kidding. That's not waste any more time and let's get started.

24
00:00:58,670 --> 00:01:08,450
Okay, so we want to add a small trail behind our bullet as it flies through space.

25
00:01:08,450 --> 00:01:10,360
How are we going to do this?

26
00:01:10,355 --> 00:01:12,335
It's actually very simple.

27
00:01:12,335 --> 00:01:15,095
We are simply going to go into the player bullet.

28
00:01:15,095 --> 00:01:19,795
And in here we can add a component which is the Trail Renderer.

29
00:01:19,790 --> 00:01:21,320
So when we click on it,

30
00:01:21,320 --> 00:01:24,200
you can see that we can add a trail.

31
00:01:24,200 --> 00:01:26,590
How are we going to be testing this trail?

32
00:01:26,585 --> 00:01:29,245
As we are going to double-click on the prefab,

33
00:01:29,240 --> 00:01:32,500
open it up in here and see what we can do.

34
00:01:32,495 --> 00:01:34,435
So first of all,

35
00:01:34,430 --> 00:01:37,060
I don't know all the elements in here.

36
00:01:37,055 --> 00:01:39,175
You can play around everything.

37
00:01:39,170 --> 00:01:42,610
You can see that one of the things that we have as the sorting layer.

38
00:01:42,605 --> 00:01:45,625
So we can choose whether it's a bullet,

39
00:01:45,620 --> 00:01:48,530
whether it's a player with whatever you want,

40
00:01:48,530 --> 00:01:49,910
I'm going to choose both.

41
00:01:49,910 --> 00:01:52,400
So how do we see the trail?

42
00:01:52,400 --> 00:01:56,510
We simply take our bullet and we start moving it around.

43
00:01:56,510 --> 00:02:00,470
So right now, this is the trail that we have.

44
00:02:00,470 --> 00:02:02,890
Yep. I know it's not that good.

45
00:02:02,885 --> 00:02:04,955
What are we going to do about?

46
00:02:04,955 --> 00:02:08,615
The first thing I want to do is I want to change the material.

47
00:02:08,615 --> 00:02:13,345
So whenever in unity you have this pink thing behind you,

48
00:02:13,340 --> 00:02:17,000
that means that there is something wrong with the material.

49
00:02:17,000 --> 00:02:19,010
So I'm going to scroll down,

50
00:02:19,010 --> 00:02:21,950
find where we have material if I remove it completely,

51
00:02:21,949 --> 00:02:24,699
you'll see that we no longer have any trail.

52
00:02:24,695 --> 00:02:27,445
You can add multiple types of material in here.

53
00:02:27,440 --> 00:02:30,530
By the way, there are a lot and there are things that

54
00:02:30,530 --> 00:02:33,670
you can import into Unity such as rock,

55
00:02:33,665 --> 00:02:34,855
such as, I don't know,

56
00:02:34,850 --> 00:02:36,580
lightning or anything you want.

57
00:02:36,575 --> 00:02:41,245
So for example, we can add this dark some kind of dark material.

58
00:02:41,240 --> 00:02:42,310
I don't know what that is.

59
00:02:42,305 --> 00:02:45,205
It's one of the default materials that we have.

60
00:02:45,200 --> 00:02:47,210
I'm just going to use we can use,

61
00:02:47,210 --> 00:02:49,730
for example, the default particle system.

62
00:02:49,730 --> 00:02:54,280
So it looks as if there is a smoke trail behind it, which is not bad.

63
00:02:54,275 --> 00:02:56,855
I might keep it. And by the way, I'm just having fun.

64
00:02:56,855 --> 00:02:58,855
I'm not sure what we're going to do.

65
00:02:58,850 --> 00:03:02,050
And let's see what can we do?

66
00:03:02,045 --> 00:03:05,855
And you can see this trail is kind of weird.

67
00:03:05,855 --> 00:03:06,985
Anyways.

68
00:03:06,980 --> 00:03:12,200
The next thing I want to do is I want to change the width of this trail so you can

69
00:03:12,200 --> 00:03:17,600
see that I can increase it or decrease it as we move through space.

70
00:03:17,600 --> 00:03:21,020
And we can also add another point right here.

71
00:03:21,020 --> 00:03:23,920
So for example, you can start it as being

72
00:03:23,915 --> 00:03:27,175
thick and then having this little trail at the end,

73
00:03:27,170 --> 00:03:30,740
so it becomes smaller as we move forward.

74
00:03:30,740 --> 00:03:33,860
And let's see what else do we have in this particle?

75
00:03:33,860 --> 00:03:36,470
We can add this type of particles,

76
00:03:36,470 --> 00:03:38,920
this type of materials actually.

77
00:03:38,915 --> 00:03:40,555
Okay, nice, not bad.

78
00:03:40,550 --> 00:03:43,880
You can add this, a normal sprite.

79
00:03:43,880 --> 00:03:47,090
And what this does is we can actually change the color.

80
00:03:47,090 --> 00:03:51,130
And here you can do with even to have blend or fixed colors.

81
00:03:51,125 --> 00:03:55,885
So 11, single color or a blend of colors.

82
00:03:55,880 --> 00:03:59,290
So you can choose, for example, here,

83
00:03:59,285 --> 00:04:01,265
the first color should be,

84
00:04:01,265 --> 00:04:04,355
let's make it around red almost.

85
00:04:04,355 --> 00:04:09,835
And the end color should be maybe white.

86
00:04:09,830 --> 00:04:13,420
Okay, So now you'll notice that as we move,

87
00:04:13,415 --> 00:04:18,875
we have at the beginning read and then right here at the end we have a white color.

88
00:04:18,875 --> 00:04:20,365
You can change the width.

89
00:04:20,360 --> 00:04:24,140
So for example, you can see right here that it's a bit big for the bullet and

90
00:04:24,140 --> 00:04:28,060
this is how the boat will be moving because it's only moving in the right direction.

91
00:04:28,055 --> 00:04:32,285
So let's make it a bit smaller, thinner.

92
00:04:32,285 --> 00:04:32,905
There we go.

93
00:04:32,900 --> 00:04:36,320
So now we have this little trail as we move through space.

94
00:04:36,320 --> 00:04:40,300
Let's see how that will look. Okay?

95
00:04:40,295 --> 00:04:42,655
And another problem is the time.

96
00:04:42,650 --> 00:04:43,930
So if we hover over it,

97
00:04:43,925 --> 00:04:45,745
how long will the tail B?

98
00:04:45,740 --> 00:04:46,910
So it's five seconds.

99
00:04:46,910 --> 00:04:50,050
I don't think five as something we want.

100
00:04:50,045 --> 00:04:51,595
I think one we'll do enough,

101
00:04:51,590 --> 00:04:53,440
maybe even less. So there you go.

102
00:04:53,435 --> 00:04:54,715
This is the trail.

103
00:04:54,710 --> 00:04:57,580
I think even 0.5 will be enough.

104
00:04:57,575 --> 00:04:59,135
So there you go.

105
00:04:59,135 --> 00:05:00,355
Get me the bullet.

106
00:05:00,350 --> 00:05:01,240
Remove.

107
00:05:01,235 --> 00:05:04,615
This will be our trail behind the bullet.

108
00:05:04,610 --> 00:05:07,550
Actually white and not that good of a color.

109
00:05:07,550 --> 00:05:12,040
I'm just going to choose some kind of orange,

110
00:05:12,035 --> 00:05:14,125
yellow, something like that.

111
00:05:14,120 --> 00:05:15,310
Let's see.

112
00:05:15,305 --> 00:05:19,085
There we go. So I think it looks good enough.

113
00:05:19,085 --> 00:05:22,125
Maybe I would like to make it a bit thinner.

114
00:05:22,129 --> 00:05:25,789
Just a little bit thinner.

115
00:05:25,790 --> 00:05:28,730
And let's try a different material just for fun.

116
00:05:28,730 --> 00:05:30,710
See how that looks.

117
00:05:30,710 --> 00:05:33,670
Nice. Not bad, I think.

118
00:05:33,665 --> 00:05:36,485
No, no, Actually, no, I don't like it.

119
00:05:36,485 --> 00:05:39,245
Maybe I should make it a bit thicker.

120
00:05:39,244 --> 00:05:41,634
We can increase the thickness at the end.

121
00:05:41,630 --> 00:05:44,410
So it's why that the beginning,

122
00:05:44,405 --> 00:05:47,545
as you can see and then it's very small.

123
00:05:47,540 --> 00:05:51,480
You can play around tested how much you want to add,

124
00:05:51,480 --> 00:05:53,420
thickness you can even change right here,

125
00:05:53,420 --> 00:05:55,730
you can see that it starts off low goes up.

126
00:05:55,730 --> 00:05:59,030
You can add another point of inflection right here.

127
00:05:59,030 --> 00:06:01,430
So for example, like that.

128
00:06:01,430 --> 00:06:03,710
Remember when we were doing the animations.

129
00:06:03,710 --> 00:06:05,450
So there you go.

130
00:06:05,450 --> 00:06:08,320
This kind of fox tail behind.

131
00:06:08,315 --> 00:06:09,745
Look how cool that is.

132
00:06:09,740 --> 00:06:12,460
You can create a lot of nice effects using

133
00:06:12,455 --> 00:06:15,595
trail if you have the time to test all of this out,

134
00:06:15,590 --> 00:06:17,630
just going to delete this.

135
00:06:17,630 --> 00:06:20,920
And let's make it normal again.

136
00:06:20,915 --> 00:06:21,815
So there you go.

137
00:06:21,815 --> 00:06:22,915
This is our trail.

138
00:06:22,910 --> 00:06:26,270
Actually, the last one was was much better honesty,

139
00:06:26,270 --> 00:06:28,960
but no worries about that for now, Let's see what.

140
00:06:28,955 --> 00:06:30,775
You can also change the shadows.

141
00:06:30,770 --> 00:06:32,500
You can have auto destruct.

142
00:06:32,495 --> 00:06:33,755
There is a lot,

143
00:06:33,755 --> 00:06:36,245
a lot of things that you can play around with.

144
00:06:36,245 --> 00:06:39,475
You can go into Unity's documentation and check everything out,

145
00:06:39,470 --> 00:06:41,450
see what other options you have.

146
00:06:41,450 --> 00:06:43,040
For example, the probes,

147
00:06:43,040 --> 00:06:45,010
camera motion, something like that.

148
00:06:45,005 --> 00:06:45,905
I'm not sure.

149
00:06:45,900 --> 00:06:46,390
Sure.

150
00:06:46,385 --> 00:06:48,305
So I'm going to save this.

151
00:06:48,305 --> 00:06:52,765
I'm going to go back into our game and let's see if we have a good trail.

152
00:06:52,760 --> 00:06:54,250
So when I shoot the bullet,

153
00:06:54,245 --> 00:06:57,265
you can see I have a small trail behind it.

154
00:06:57,260 --> 00:06:59,470
It's not that good.

155
00:06:59,465 --> 00:07:02,515
It's not the way I would like it to be.

156
00:07:02,510 --> 00:07:06,130
But you can see it's just a small trail behind.

157
00:07:06,125 --> 00:07:08,845
So wait for the bullets to be destroyed.

158
00:07:08,840 --> 00:07:15,080
Try this again. And if you've noticed there is not one bullet,

159
00:07:15,080 --> 00:07:18,380
there are two bullets right here.

160
00:07:18,380 --> 00:07:19,600
And why is that?

161
00:07:19,595 --> 00:07:22,945
What do you think the problem isn't here?

162
00:07:22,940 --> 00:07:26,390
And the reason that we have two bullets is

163
00:07:26,390 --> 00:07:29,800
because if we go back into our script right here,

164
00:07:29,795 --> 00:07:36,845
you'll notice that if we press the mouse button during a frame or if we keep pressing it,

165
00:07:36,845 --> 00:07:39,965
we our instantiating a bullet.

166
00:07:39,965 --> 00:07:42,265
So in order to fix this,

167
00:07:42,260 --> 00:07:46,460
we are going to give the option to the player to choose whether this

168
00:07:46,460 --> 00:07:51,050
is going to be an automatic or not an automatic weapon.

169
00:07:51,050 --> 00:07:55,270
Now, I will remind you that this will be moved to

170
00:07:55,265 --> 00:07:59,635
another script because we don't want to handle this in the player script.

171
00:07:59,630 --> 00:08:01,760
We will delve deeper into why.

172
00:08:01,760 --> 00:08:04,000
Because let me just tell you from now,

173
00:08:03,995 --> 00:08:07,915
because having an automatic weapon is not the player controller job.

174
00:08:07,910 --> 00:08:09,740
It should be on a different script.

175
00:08:09,740 --> 00:08:13,400
But for now, let's just fix this problem.

176
00:08:13,400 --> 00:08:17,540
I'm going to create a serialized field which will be of type Boolean.

177
00:08:17,540 --> 00:08:24,180
And I'm going to call it is weapon auto magic.

178
00:08:24,175 --> 00:08:27,445
So if the weapon is automatic,

179
00:08:27,444 --> 00:08:29,784
we are going to change the conditions.

180
00:08:29,785 --> 00:08:34,845
So if the weapon is not automatic and we press the most button down,

181
00:08:34,840 --> 00:08:36,970
we will immediately instantiate.

182
00:08:36,970 --> 00:08:41,200
So just like we had the or which script,

183
00:08:41,200 --> 00:08:43,170
I'm not sure, was it the script?

184
00:08:43,165 --> 00:08:46,465
Which script that we add an or?

185
00:08:46,530 --> 00:08:48,930
Or we haven't all, okay,

186
00:08:48,925 --> 00:08:50,695
so we have the end.

187
00:08:50,695 --> 00:08:52,305
What does this symbol mean?

188
00:08:52,300 --> 00:08:53,430
Let me just finish.

189
00:08:53,425 --> 00:08:55,945
Is weapon automatic?

190
00:08:55,945 --> 00:08:58,005
And just like we've said previously,

191
00:08:58,000 --> 00:09:00,160
when we have an exclamation mark,

192
00:09:00,160 --> 00:09:02,450
this means that if this one,

193
00:09:02,445 --> 00:09:05,185
if the weapon is automatic,

194
00:09:05,180 --> 00:09:08,570
this whole condition will be false.

195
00:09:08,570 --> 00:09:10,810
So if is automatic is true,

196
00:09:10,805 --> 00:09:14,365
this exclamation mark behind that makes it false.

197
00:09:14,360 --> 00:09:21,770
But that understood this n means both conditions need to be true in order to instantiate.

198
00:09:21,770 --> 00:09:23,260
So what do we have here?

199
00:09:23,255 --> 00:09:28,945
If the weapon is not automatic with the exclamation mark,

200
00:09:28,940 --> 00:09:31,250
if the weapon is not automatically,

201
00:09:31,250 --> 00:09:35,780
this whole condition becomes true. Why is that?

202
00:09:35,780 --> 00:09:38,190
Because if the weapon is not automatic,

203
00:09:38,194 --> 00:09:44,284
this is automatic by itself without the exclamation mark is false.

204
00:09:44,284 --> 00:09:48,364
With the exclamation mark, it becomes true.

205
00:09:48,365 --> 00:09:51,205
And if we are pressing the button,

206
00:09:51,200 --> 00:09:53,560
we instantiate the bullet immediately.

207
00:09:53,555 --> 00:10:00,805
And if the we are holding down the button and the weapon is automatic,

208
00:10:00,800 --> 00:10:04,550
then we are going to have our shot counter.

209
00:10:04,550 --> 00:10:06,500
Let me do this again.

210
00:10:06,500 --> 00:10:15,230
And actually let me go ahead and print in here in the debug dot log.

211
00:10:15,230 --> 00:10:21,020
If the exclamation mark is automatic.

212
00:10:21,020 --> 00:10:23,650
So you can see for yourself, save that.

213
00:10:23,645 --> 00:10:26,255
So again, what's happening in here?

214
00:10:26,255 --> 00:10:30,895
We can go right now and choose whether a weapon is automatic or not.

215
00:10:30,890 --> 00:10:34,440
How does this help us if the weapon is automatic?

216
00:10:34,444 --> 00:10:37,104
And these two symbols right here,

217
00:10:37,100 --> 00:10:39,920
and we are holding down the mouse button.

218
00:10:39,920 --> 00:10:42,710
We will have the shot counter and we will have

219
00:10:42,710 --> 00:10:46,220
shooting constantly depending on the time between the shots.

220
00:10:46,220 --> 00:10:51,320
But if the weapon or the weapon is not automatic,

221
00:10:51,319 --> 00:10:55,759
that means the weapon automatic is false.

222
00:10:55,760 --> 00:10:59,560
Which means when we add an exclamation mark behind it,

223
00:10:59,555 --> 00:11:01,105
it makes it true.

224
00:11:01,100 --> 00:11:07,010
So this entire condition right here is true and we are hitting

225
00:11:07,010 --> 00:11:12,880
the mouse button once we instantiate immediately without any delay between them.

226
00:11:12,875 --> 00:11:15,365
And we also have this to display to make sure you

227
00:11:15,365 --> 00:11:18,835
understand how the exclamation mark works.

228
00:11:18,830 --> 00:11:21,650
You can see right here exclamation mark automatic.

229
00:11:21,650 --> 00:11:22,990
Back in our game.

230
00:11:22,985 --> 00:11:24,845
We run our game.

231
00:11:24,845 --> 00:11:26,795
You'll notice console, there we go.

232
00:11:26,795 --> 00:11:28,075
This is a small error.

233
00:11:28,070 --> 00:11:29,500
Don't worry about it.

234
00:11:29,495 --> 00:11:32,065
I'm going to clear this and you can see that it's false.

235
00:11:32,060 --> 00:11:34,430
False, false wild is automatic, is true.

236
00:11:34,430 --> 00:11:36,460
When I turn it off,

237
00:11:36,455 --> 00:11:38,545
you can see it becomes true.

238
00:11:38,540 --> 00:11:43,720
You can see the messages being sent right here collapsed upon each other.

239
00:11:43,715 --> 00:11:48,215
So now, if I don't have a weapon automatic as false,

240
00:11:48,215 --> 00:11:50,045
if I hold down the mouse button,

241
00:11:50,045 --> 00:11:52,585
you can see that I only shoot once.

242
00:11:52,580 --> 00:11:54,260
If I have it on automatic,

243
00:11:54,260 --> 00:11:55,700
I hold down the mouse button.

244
00:11:55,700 --> 00:11:57,820
I have a lot of shots.

245
00:11:57,815 --> 00:12:02,575
And the great thing about this is just wait for the bullets to all be destroyed.

246
00:12:02,570 --> 00:12:04,550
Now when I press the button,

247
00:12:04,550 --> 00:12:06,200
once, there you go,

248
00:12:06,200 --> 00:12:08,020
we only have one bullet.

249
00:12:08,015 --> 00:12:14,095
So we fixed the problem of having a magic bullet will save that if you want,

250
00:12:14,090 --> 00:12:15,340
we can adjust the trail.

251
00:12:15,335 --> 00:12:17,215
I just did it a bit fast.

252
00:12:17,210 --> 00:12:18,820
Have your time, have fun,

253
00:12:18,815 --> 00:12:23,125
enjoy creating some weird trail with a lot of colors and so on.

254
00:12:23,120 --> 00:12:26,560
And I believe this is the last video in this section,

255
00:12:26,555 --> 00:12:28,075
and the next section,

256
00:12:28,070 --> 00:12:32,300
we are going to be setting up the enemies that we want to kill.

257
00:12:32,300 --> 00:12:37,750
Because what's the point of having bullets if we don't have anybody to kill them with.

258
00:12:37,745 --> 00:12:41,185
So make sure to always commit your changes.

259
00:12:41,180 --> 00:12:44,790
And I'll see you in the next video.

