Welcome back, my fellow game developers.
In this video, we've added a Trail Renderer to our bullet.
I'm going to make it a bit exaggerated so you can
see clearly what's happening when we run our game.
When we shoot our bullet.
There you go.
You can see that it has some kind of trailed behind it.
I'm going to make it a bit bigger.
So you clearly see what's going on.
I shoot a bullet.
Well, there you go.
You can see our cool looking trail,
the trails behind the bullet.
Actually it's not perfect.
It's not that nice.
But I left the creativity part to you because while I know myself,
I'm not that creative with that said,
let's not waste any more time.
We fix a small problem that we had,
but we didn't see before maybe you've
noticed it and thought moon, Michael forgot something.
What is E such a burden structs you.
No, no, I'm kidding. That's not waste any more time and let's get started.
Okay, so we want to add a small trail behind our bullet as it flies through space.
How are we going to do this?
It's actually very simple.
We are simply going to go into the player bullet.
And in here we can add a component which is the Trail Renderer.
So when we click on it,
you can see that we can add a trail.
How are we going to be testing this trail?
As we are going to double-click on the prefab,
open it up in here and see what we can do.
So first of all,
I don't know all the elements in here.
You can play around everything.
You can see that one of the things that we have as the sorting layer.
So we can choose whether it's a bullet,
whether it's a player with whatever you want,
I'm going to choose both.
So how do we see the trail?
We simply take our bullet and we start moving it around.
So right now, this is the trail that we have.
Yep. I know it's not that good.
What are we going to do about?
The first thing I want to do is I want to change the material.
So whenever in unity you have this pink thing behind you,
that means that there is something wrong with the material.
So I'm going to scroll down,
find where we have material if I remove it completely,
you'll see that we no longer have any trail.
You can add multiple types of material in here.
By the way, there are a lot and there are things that
you can import into Unity such as rock,
such as, I don't know,
lightning or anything you want.
So for example, we can add this dark some kind of dark material.
I don't know what that is.
It's one of the default materials that we have.
I'm just going to use we can use,
for example, the default particle system.
So it looks as if there is a smoke trail behind it, which is not bad.
I might keep it. And by the way, I'm just having fun.
I'm not sure what we're going to do.
And let's see what can we do?
And you can see this trail is kind of weird.
Anyways.
The next thing I want to do is I want to change the width of this trail so you can
see that I can increase it or decrease it as we move through space.
And we can also add another point right here.
So for example, you can start it as being
thick and then having this little trail at the end,
so it becomes smaller as we move forward.
And let's see what else do we have in this particle?
We can add this type of particles,
this type of materials actually.
Okay, nice, not bad.
You can add this, a normal sprite.
And what this does is we can actually change the color.
And here you can do with even to have blend or fixed colors.
So 11, single color or a blend of colors.
So you can choose, for example, here,
the first color should be,
let's make it around red almost.
And the end color should be maybe white.
Okay, So now you'll notice that as we move,
we have at the beginning read and then right here at the end we have a white color.
You can change the width.
So for example, you can see right here that it's a bit big for the bullet and
this is how the boat will be moving because it's only moving in the right direction.
So let's make it a bit smaller, thinner.
There we go.
So now we have this little trail as we move through space.
Let's see how that will look. Okay?
And another problem is the time.
So if we hover over it,
how long will the tail B?
So it's five seconds.
I don't think five as something we want.
I think one we'll do enough,
maybe even less. So there you go.
This is the trail.
I think even 0.5 will be enough.
So there you go.
Get me the bullet.
Remove.
This will be our trail behind the bullet.
Actually white and not that good of a color.
I'm just going to choose some kind of orange,
yellow, something like that.
Let's see.
There we go. So I think it looks good enough.
Maybe I would like to make it a bit thinner.
Just a little bit thinner.
And let's try a different material just for fun.
See how that looks.
Nice. Not bad, I think.
No, no, Actually, no, I don't like it.
Maybe I should make it a bit thicker.
We can increase the thickness at the end.
So it's why that the beginning,
as you can see and then it's very small.
You can play around tested how much you want to add,
thickness you can even change right here,
you can see that it starts off low goes up.
You can add another point of inflection right here.
So for example, like that.
Remember when we were doing the animations.
So there you go.
This kind of fox tail behind.
Look how cool that is.
You can create a lot of nice effects using
trail if you have the time to test all of this out,
just going to delete this.
And let's make it normal again.
So there you go.
This is our trail.
Actually, the last one was was much better honesty,
but no worries about that for now, Let's see what.
You can also change the shadows.
You can have auto destruct.
There is a lot,
a lot of things that you can play around with.
You can go into Unity's documentation and check everything out,
see what other options you have.
For example, the probes,
camera motion, something like that.
I'm not sure.
Sure.
So I'm going to save this.
I'm going to go back into our game and let's see if we have a good trail.
So when I shoot the bullet,
you can see I have a small trail behind it.
It's not that good.
It's not the way I would like it to be.
But you can see it's just a small trail behind.
So wait for the bullets to be destroyed.
Try this again. And if you've noticed there is not one bullet,
there are two bullets right here.
And why is that?
What do you think the problem isn't here?
And the reason that we have two bullets is
because if we go back into our script right here,
you'll notice that if we press the mouse button during a frame or if we keep pressing it,
we our instantiating a bullet.
So in order to fix this,
we are going to give the option to the player to choose whether this
is going to be an automatic or not an automatic weapon.
Now, I will remind you that this will be moved to
another script because we don't want to handle this in the player script.
We will delve deeper into why.
Because let me just tell you from now,
because having an automatic weapon is not the player controller job.
It should be on a different script.
But for now, let's just fix this problem.
I'm going to create a serialized field which will be of type Boolean.
And I'm going to call it is weapon auto magic.
So if the weapon is automatic,
we are going to change the conditions.
So if the weapon is not automatic and we press the most button down,
we will immediately instantiate.
So just like we had the or which script,
I'm not sure, was it the script?
Which script that we add an or?
Or we haven't all, okay,
so we have the end.
What does this symbol mean?
Let me just finish.
Is weapon automatic?
And just like we've said previously,
when we have an exclamation mark,
this means that if this one,
if the weapon is automatic,
this whole condition will be false.
So if is automatic is true,
this exclamation mark behind that makes it false.
But that understood this n means both conditions need to be true in order to instantiate.
So what do we have here?
If the weapon is not automatic with the exclamation mark,
if the weapon is not automatically,
this whole condition becomes true. Why is that?
Because if the weapon is not automatic,
this is automatic by itself without the exclamation mark is false.
With the exclamation mark, it becomes true.
And if we are pressing the button,
we instantiate the bullet immediately.
And if the we are holding down the button and the weapon is automatic,
then we are going to have our shot counter.
Let me do this again.
And actually let me go ahead and print in here in the debug dot log.
If the exclamation mark is automatic.
So you can see for yourself, save that.
So again, what's happening in here?
We can go right now and choose whether a weapon is automatic or not.
How does this help us if the weapon is automatic?
And these two symbols right here,
and we are holding down the mouse button.
We will have the shot counter and we will have
shooting constantly depending on the time between the shots.
But if the weapon or the weapon is not automatic,
that means the weapon automatic is false.
Which means when we add an exclamation mark behind it,
it makes it true.
So this entire condition right here is true and we are hitting
the mouse button once we instantiate immediately without any delay between them.
And we also have this to display to make sure you
understand how the exclamation mark works.
You can see right here exclamation mark automatic.
Back in our game.
We run our game.
You'll notice console, there we go.
This is a small error.
Don't worry about it.
I'm going to clear this and you can see that it's false.
False, false wild is automatic, is true.
When I turn it off,
you can see it becomes true.
You can see the messages being sent right here collapsed upon each other.
So now, if I don't have a weapon automatic as false,
if I hold down the mouse button,
you can see that I only shoot once.
If I have it on automatic,
I hold down the mouse button.
I have a lot of shots.
And the great thing about this is just wait for the bullets to all be destroyed.
Now when I press the button,
once, there you go,
we only have one bullet.
So we fixed the problem of having a magic bullet will save that if you want,
we can adjust the trail.
I just did it a bit fast.
Have your time, have fun,
enjoy creating some weird trail with a lot of colors and so on.
And I believe this is the last video in this section,
and the next section,
we are going to be setting up the enemies that we want to kill.
Because what's the point of having bullets if we don't have anybody to kill them with.
So make sure to always commit your changes.
And I'll see you in the next video.