We need to set our line renderer component.
So we're going to do that.
So let's select our enemy one GameObject in the hierarchy.
And let's click on this add component.
And we're going to add a line renderer component in order to see the way that this enemy GameObject
shooting on our player GameObject.
So let's add a line renderer component and let's go to Line Renderer component.
And we're going to scroll down and let's move over to this material.
As you can see it says non material.
So we need to choose a material in order to see that.
So let's click over here.
And we need to choose a default material.
So you can just type it over here default.
Or you can simply click on this default as well over here.
And we can see we don't have the width.
So what we're going to do we're going to remove this line renderer component.
And we're going to add one more time.
Basically we're gonna add that renderer line renderer component one more time to basically able to get
the width.
So let's right click on it and let's remove component.
And we're going to add the line renderer component once again.
So let's click on this component.
And we're going to add the line renderer.
Let's go to materials.
And now we can see the width over here.
So that's why we just remove that.
And then we just attach it one more time because we we wasn't able to see this width.
So that is the reason.
So we're going to move over to material.
And we're going to see we're going to select default.
And let's go to size position.
And we're going to set the x something like this much.
And we can press down F in order to focus on that.
So we need to play around with this value.
So I'm going to play around with this x.
So now we can see it's just getting resized.
So with I'm going to choose the x something like four.
And I want to make the width a little bit.
Uh you can simply say uh thickness.
So we're going to drag down this width.
So as you can see we can able to see our chain I'm gonna move this up a little bit.
In order to be able to see that.
So I'm gonna move this in the Y.
Something like this.
In the X as well.
So I guess this is pretty much fine.
And we are now able to see our line renderer component.
And I'm gonna choose a yellow color, something like that.
So I can assume that the yellow one just gonna shoot out from this Army game object.
So I'm going to make the color yellow something like that.
So let's click on this color and let's click over here.
And we're going to choose a yellow color something like this.
And we're going to select this one.
And let's delete that.
And this is fine.
And we need to make our thickness thickness a little bit down.
So we can still able to see.
You can simply say it's too much uh width.
So we're going to drag a little bit down something this much I guess this is pretty much fine by now.
And what we need to do now, we need a reference of this renderer.
Line renderer component.
Then we can set that up.
So let's open up our animation script and let's go to the top of our class because we need to grab the
reference first.
So we're going to make a public line renderer.
So we basically doing the same same thing as we have done in our player game object.
And we're going to call it something like LR.
And let's close that up with semicolon.
And we're going to move over to this start function.
In this start of the game we just want to disable this LR or this line renderer component.
But once this enemy game object shoot out uh shoot out, then we're going to enable this line renderer
component.
So we're going to move over to start function.
And we're going to move over to LR.
Then we're going to use this dot enable.
And we're going to set equal to false.
Basically we just disabling that.
And we're going to press down Ctrl s in order to save our script.
And let's move out to unity because we need to drag the reference in our LR uh slot.
So we're going to have the reference.
Then we can set that up.
So just wait for it to compile.
And once it's done, we need to drag the reference in that corresponding slot.
It's going to take a few moments, so just wait.
And once it's done you are ready to do that.
So as soon as our enemy script gets compiled we can see LR in it.
Says non line renderers basically means empty.
So we're going to select this line, run a line renderer and we're going to drag it right there.
Now we have the reference as you can see.
And we also want to go over to overrides.
And then we're going to click on this apply to change in the prefab.
And let's go to script now.
And let's move over to that line of code where we're shooting.
So we're shooting over here as you can see.
So what we need to do.
So once we shoot firstly we need to need to enable our line renderer component.
And then we're going to set the position.
So let's do that.
So we're going to move over to script.
So once we're calling this shoot raycast function because we basically need to enable our line renderer.
So I'm going to move over to line renderer component.
And we're going to use this enable.
And we're going to set equal to true.
Basically we're just enabling that.
And after that we need to set the position.
And in order to set the position uh we need to use LR dot set position function.
So what I'm going to do I'm going to set over here.
So I'm going to bring down this.
Or you can just leave it that and I'm going to do it over here something like that.
So we're going to store the first position.
So let's suppose this anime game object uh game object shoot on our this player game object.
Then what we're going to do, uh, we're gonna set the position.
So the first, uh, position or where we're gonna shoot out the ray, we're going to store that position
into zero index.
So and then we're going to set the second position basically where the ray collided with.
So we that ray is going to collide with this player game object.
So where it's collided with we're going to uh As basically that will be the second position and we're
going to store the position into one index.
So let me show you how you can do that.
So let's go to script.
So the first position we're going to set.
So we need to use this alert dot set position function in order to set the position.
So we're going to store the first position.
So the first position we're going to store in this zero index.
So we need to pass the index as a first argument comma.
And we have to store the position or which position we want to store in this zero index.
So we're going to store the position where we shooting out the array.
So we're gonna shoot out the array.
We do know from this anime game object Fire point.
We created the fire point as using.
So now store that position or where we shooting out.
We're gonna store that position into this zero index.
So what we're going to do type of what we're going to do over here.
We're going to pass fire point dot position.
So we're going to pass fire point dot position basically means where we're shooting out the array.
Uh, we do know we're going to shoot out the ray from the top of our enemy game object gun.
So fire point position and let's close that up with semicolon.
And now we're going to move over to this hit info.
And if hit info is true basically means the ray really colliding with this uh, player game object.
So where it's collided with this player game object.
So we're going to store that position in one index.
So we store it the first position in zero index.
And we're going to store the second position where the collided with this player game object.
We're gonna store that position into one index.
So let's do that.
And we colliding over here as you can see.
And we printing out a message in the console says player takes damage.
And after printing out or doing like that I'm going to set the position as well, which is the next
position.
Or you can simply say simply say the second position.
So we're going to use this last set position function one more time in order to set the position.
So we're going to set the second position into one index.
So we need to pass the index as a first argument comma, and we have to pass the position or where the
collided with.
We're going to store that position into this one index.
So we're going to pass over here hit info dot point and then close that up with semicolon.
So hit info dot point basically means the where the collided with our player game object.
So the array is just going to collide with this player game object.
Once our player game object gets in attack range.
So the range is going to collide.
So we just taking that position where the collided with with this player game object.
And we're storing this position into one index as you can see.
So this hit info point basically means where the collided with the player game object.
But let's suppose the don't collide with this player game object.
And let's suppose this player game object jumps, but this enemy game object is still gonna shoot on
this player game object bits, because it's gonna be in attack range.
So that's why.
So in that situation we need to shoot out the ray in the air.
in the air, something like that.
We need to do that.
So what we're going to do, we're going to use this else condition.
So else if the ray is don't collide with our player game object means our, uh, enemy need to shoot
in the air.
So we need to set the position.
So we're going to use this one more time which is LR dot set position function.
And we do know as a first argument it's going to take the position.
So we're going to store the position in this one index.
And we do know we store the first position or where we shoot it out the ray uh into this zero index.
And we're just setting the second position or we're storing the second position into this one index.
So over here it's not going to collide at all with this player game object.
So we're going to shoot out the ray in the air.
So we need to still want to see the line renderer with how much length of the ray is it.
And we just want to see that.
Still want to see that.
So what we're going to do over here over here we're going to pass.
So transform.position.
Firstly we're going to pass fire point dot position.
Fire point dot position.
Fire point dot position basically means the current position or from where we shouted out the ray.
So we're going to shoot out the ray from this fire point position.
And on top of that, we're gonna multiply.
We're going to add on top of that the direction, and we're going to multiply the length of the ray.
So we're going to type this transform dot right.
Transform dot right.
Basically means in which direction the player is facing.
Basically this player is facing to the left direction.
But in this situation transform that right going to be this direction which is the right one.
But we just want to shoot out the ray in the left direction.
So that's why we're going to put the top top of this.
Or we can simply type transform dot left as well.
Or we can simply do transform dot right.
And you can just put this into a bracket.
So just put it into brackets.
And then before you just type transform dot right.
Just put minus and now this minus.
Just going to reference the left direction.
We do no transform dot right basically means this direction.
And we're just putting minus.
It's basically just going to reference the left direction.
And we're going to multiply that direction with our length of the ray which is distance we do know.
So we're going to able to see our line renderer with the that much of length of the ray.
So we're going to multiply this direction with our distance basically means the length of the ray.
And now we're going to close that off with semicolon.
So firstly what we have done we just we have taken the five pointer position basically means where we
just are shooting out the ray.
So transform dot position and top of that we just adding multiply.
We just taking our direction.
And then we just multiplying with our length of the ray as you can see.
So that way it's just going to be in the left direction with our distance parameter, with our length
of the ray which is ten.
We set, as you can see underneath our anime script.
So we're going to press down Ctrl S in order to save our script.
And let's move over to unity.
And let's suppose the array is really collided with that player game object.
Then what we have done over here, as you can see, uh, we uh, over here, we can see the second position
basically where the array hit, we just store it that second position in this one index.
And if the array don't collide with our player game object in that we still able to see our array.
As you can see firstly we're taking the position.
And on top of that we just multiplying with our uh direction as well as we uh basically we just taking
the direction and then multiplying with our distance or the length of the array.
So we're gonna still able to see that array.
So now if we click on this play button you will see that uh line renderer.
Line renderer.
As soon as the game start you will see this gonna be disabled, that line renderer component because
we know we just disabling.
But once this enemy game object on a attack on just gonna shoot on this player game object, you will
see the array.
So just wait.
And as you can see, as soon as we get in attack range, we able to see our array.
And if we even jump, we still able to see our array in the air.
But we need to disable this ray once our player game object is not in attack range or something like
that, it's just out of this enemy game object attack range.
So we need to disable that.
So let's get out of play mode.
As you can see in the console, we just printing out a message saying disable alert.
So we're going to double click on that.
Basically what we have done we have done all of these things in this AI enumerator function.
And we do know that we use this function in order to release some line of code.
And we're doing it over here as you can see.
So after this amount of time.
So use this over here as I did here which is return new point version and you have to put the time in
these brackets in.
Basically, after this amount of time, you can do whatever you just want to do.
So after this amount of time, I just want to disable or other line renderer component, and I have
chosen a pretty small number, as you can see, because I want a pretty small short period of time in
order to disable the laser.
But once this anime game object just sorry player game object gets in attack range, it's gonna enable
the line renderer component, and after a short period of time or pretty with pretty much small time,
I just want to disable that renderer component as we're gonna do that.
Basically, we just want to disable.
And as you can see, we're just printing out a message in the console says disable line renderer or
LR component.
So instead of printing out this message we're gonna disable our line renderer component.
So we're going to use this LR dot enable.
And we're going to set equal to false.
Basically, we disabling that line renderer component after this amount of time.
As you can see, and we have the we have approached the same way we have done in this player game object.
So you can just, uh, take a look on that player shooting scripting as well if you just want to get
it more.
Uh, of course I will have a video in the resources as well.
If you just want to learn more deeply about line renderer component, as well as about shooting, shooting
how you can shoot by using raycast.
And we're going to press down Ctrl S in order to save our script.
And now let's move over to unity.
So we will see after 0.12 second the line renderer just gonna be disabled by itself.
But once we shoot one more time, it's just gonna enable.
And after that amount of time it's gonna be disabled.
Because as you can see, as soon as we calling this shoot raycast function, we enabling.
And after doing all of these things and after this amount of time, we disabling as you can see.
So let's go to unity now.
And let's click on this play button in the top in order to check it.
So just wait for to compile and let's have a look.
You will see that.
So let's get in attack range of this enemy game object.
And as soon as we can see get in attack range we can see the line rendered.
Just get enabled and it's just getting disabled as soon as we out of attack range.
And also it just disabling after something like 0.12 second.
But it seems like our enemy game object is shooting a lot at one moment.
So we need to stop doing that.
So let's get out of play mode.
So what we're gonna do, we're gonna make we're gonna tweak the animation.
Basically, we need to select our enemy one GameObject in the hierarchy.
Let's go to animation tab.
And then we can see we have the shooting.
So click over here in order to choose the animation.
So this is the animation clip.
So what I want to do, I just want to copy the first frame.
And then I'm going to paste it uh, a lot of times to just uh, delay the shooting thing because I just
want to move this.
You can simply say this one a little bit further away.
So this player game object gonna have a little moment to shoot on this, uh, enemy game object as well.
And this enemy game object, just gonna take a few moments to shoot on this player game object as well.
And we don't want to shoot a lot of time at once.
We just want to shoot something like, uh, something like 0.1 second or sorry, uh, after one second
or after 1.2.
Basically we just want to choose a little bit bigger number.
So what we're going to do, we're going to select all of this frame basically last three.
And we're going to move it a little bit further away in animation tab.
So you can just select like this.
And we're going to move it somewhere over here something like that in ten.
So I guess I'm gonna move it something like seven.
And also, we need to we're gonna drag this shoot function somewhere over here because this function
is responsible for shooting out, as you can see.
And we're calling the shoot function over here.
So we're going to also move this one a little bit further away.
So we're going to have a little time to shoot on this enemy game object as well.
And make sure you just hit this red button over here in order to capture the animation as you're not
able to do it.
So I'm going to click on this red button in order to record the animation.
And I'm going to click on that once again and to capture it.
Or you can just leave it like that.
It's automatically going to be captured.
And now we're gonna able to see.
So let's select the console and let's click on this play button because I want to see that message.
So you will see this enemy game object.
Now it's gonna take a few moments to shoot on this player game object because we just drag it that function
a little bit further away in animation tab as well as we just drag it some animation, Nation a basically
individual spread of shooting animation, as you can see.
Anime is now taking a little bit more movement in order to shoot, so so you can just drag it a little
bit further away as well.
If you just want to just get a perfect number, you can do that.
So I'm going to get out of play mode and I'm going to do it.
So I'm going to select my anime -- game object in the hierarchy.
Let's move to animation tab and then animation.
And I'm going to still want to move a little bit further away something like one.
So let's select all of this frame.
But before we do let's click on this red button in order to record the animation.
And I'm going to select all of these three.
And I'm going to drag it a little bit further away as well as we need to drag this event a little bit
further away.
Or you can simply say this should function.
So it's going to take a moment to shoot on this player game object.
In order to shoot on this player game object.
And I'm going to click on this red button one more time in order to capture the animation.
Now it should be fine by now.
So let's have a look on this one more time.
I'm going to make my player speed a little bit fast or what we can simply do.
We can disable this line render component in this uh, by default we can just disable that so we can
select our enemy one game object.
Let's go to Inspector Line renderer component.
And I'm going to uncheck uncheck.
It basically means you just disabling that.
And we also disabling as soon as the game started.
As you've seen in the start function, we already have done.
And I'm going to do the same thing with this player game, uh, with this player game object, because
we can see one more line render component is active.
So we need to disable that.
So I'm going to select my player game object because in this player game object I have attached this
line renderer component as you can see in the inspector.
So I'm going to uncheck.
It means we just disabling that.
And now as you can see it's uh seems pretty much uh pretty much clean by now.
And also I want to move this, uh, align Aline render component app.
Something like this.
Or we need to open up and let's take a look on that later.
And let's click on this play button in the top in order to check.
So I forgot to speed up my player speed.
So I really apologize.
We can do in play mode as well, so I can simply select my player game object in the hierarchy and I
can make the speed over here something like three, in order to make it a little bit faster.
As you can see now, it's pretty much fine.
This enemy is just taking a little moment in order to shoot on our player game object.
So you can just play around with any number that you would like to go with.
So you can just check that out.
So I'm gonna get out of play mode, and now we're gonna move over to overrides and we're gonna apply
all.
And also we're gonna press down control S on our keyboard in order to save our project.
Or we can simply go over to top left file, then click on the save button over here in order to save
your project.