Would be nice if we able to see our array.
So what we will do?
We're going to add a line render component in order to able able to see our array.
So let's do that.
We're going to select our player GameObject in the hierarchy.
And let's click add.
Let's click on this add component.
And we're going to add a component called Line Renderer.
So we're going to type the component name which is line renderer.
As you can see, as soon as we type it gets pop up.
And we're going to click there in order to attach.
So make sure you just go to this line render component.
Then materials you're going to find in the bottom.
So scroll down a bit and materials and we can see it says none materials.
So just click there and then select this default.
Or you can simply type over here as well which is the default.
And we're going to attach.
And after doing that just move over to this position and then size.
And we're going to make in the X something like five in order to be able to see.
So as you can see we can see our array and uh, we can see or we can set the position as well.
So I'm going to move over to this index and we can set the position.
So I'm going to move over to in the Y a little bit up something like this.
Sorry one and one we're going to do.
As you can see now we are able to see our line renderer and we're going to adjust it.
So uh so move over to this width and we're going to make it a little bit thickness.
So we can simply select this red line.
And we're gonna drag it down to make it a little bit thicker.
Something much this.
And I'm going to make it a little bit with a little bit up something around over here.
And if you want to choose any color you can just move over to this color.
Then you can choose the color.
So in the right side click over here this and then click on this color.
And you can choose the color that you want to choose.
And I'm going to select this one and I'm going to delete it.
So as soon as we delete we can see it's red.
And you can choose the color which color you want to set with.
But I'm gonna move I'm gonna basically what I'm gonna do, I'm gonna go with this red color.
And now what we will do, we're gonna open up our player script in order to set this line render position
as well as, uh, the where we just want to do that.
So we also need to set this to be enable or disable.
As you can see we can enable that as well as we can disable that.
So let's open up our player script.
And we need a reference of this line renderer component in order to set that.
So let's open up our player script by double clicking on it.
And we will move to the top of our class.
And let's create another public variable.
So let's click a public.
And the component we're looking for is a line renderer.
So we're going to type line renderer.
And we can call it something like LR, short for line renderer, and then close that off with semicolon
control for control S for saving your script and move over to unity.
So underneath our player Skip we're going to see another fill.
And that will be line renderer.
So what we need to do there we need to basically drag the line renderer component in there.
So we're going to have the reference.
And then we can set the position.
So just wait.
As you can see LR and it says line renderer.
So we're going to take our line render component.
And we're going to drag it there.
And we can see now we have a reference called player line Renderer.
And now we are ready to set the position as well as the index.
So let's open up our player script and what we will do.
We're going to move over to this start function.
And we do no start function get call in the start of the game.
So in this start of the game what we want we just want to disable this renderer.
So if we move to unity and then this line runner line renderer component and we can check it or uncheck
it, check it, uncheck it basically means we just enabling or disabling it.
So I'm gonna uh, what I'm gonna do, we're gonna do it with our script.
So let's, let's move over to script.
And then in the start of the game I just want to disable this blind renderer component.
Why?
Because we don't want this to be active.
But once our player GameObject shoot out a ray something, once we click left mouse button, then we're
gonna enable this line renderer.
So basically that is the thing.
So let's go to script and we're going to say line renderer and dot.
We're going to use this enable parameter in order to set that.
And we're going to set equal to false.
False basically means we just disabling or if you pass through means enabling.
So we just moving over to this line renderer component.
And then we just disabling it in the start of the game.
But once we click left mouse button then we need to enable this.
So let's go to script now.
And why are we doing.
We just uh doing over here in shoot function as you can see.
So we're going to do it over here.
Uh, so uh, instead of using this shoot function we're going to use AI enumerator.
Why?
Uh, basically we want to enable this blind runner component a few second or a pretty short time, and
then we're gonna disable that right away.
We're going to enable for pretty short time.
And after that we're gonna disable right away.
Uh, after that or a short period of time, something like a millisecond or even we're gonna enable
that blind runner point 5 or 0.2 second for a short moment.
And after that we're gonna disable that.
So that's why we're going to use this AI enumerator.
So we need to get rid of this, uh, void.
And we have to use this AI enumerator.
So before you use that, make sure you just go to the top of your class and then include this name namespace.
It's called using sorry as using a system dot collection.
So you need to use this system dot collection in top of your, uh, unity class.
So make sure you just go to top of your class and then use this namespace call using system dot collection.
And it's gonna allow us to use I enumerator function.
So we're going to do it over here.
So we're going to get of uh our void.
And we're going to type this I enumerator.
Now we able to see.
So why we using this I enumerator function.
Because we're gonna wait for some moment and after that we're gonna disable that array right away.
Or that line renderer for enabling for, uh, for enabling a few moments or few seconds.
And after that, we're gonna disable.
So this enumerator function is allow us to delay some line of code.
Or if you want to do a, uh, if you want to do some specific things after some certain period of time,
then you can use this AI enumerator function in order to do that and make sure why're you calling your
function?
You need to call it in a different way.
So we just simply take the shift function or the name of the function.
As you can see, instead of using that what we have to do, we need to use this startcoroutine.
It's kind of a bit weird, but you have to use that and then make first bracket.
And in this bracket you need to, uh, put the function that you want to call.
So we're going to call this function.
So that's why in this brackets we need to type the function name.
So in our case shoot and make sure you make this first bracket because that itself a function.
And then close that up with semicolon.
So you need to call the function in this startcoroutine.
It's kind of a bit weird but we have to do it.
So we're using this I inner I enumerator function in order to delay some line of code.
So what we're going to do now we're going to use this alert.
So once we're calling the shoot function that what we want to what we have to do, we need to enable
that this way.
So that's why we will go to LR basically line runner line renderer.
And then we're going to use this enable function in order to enable that.
And we're going to set equal to true.
Basically we just enable and after short period of time we're going to disable that.
So that's why uh we're going to use this l return new wait for second.
So you can use this new wait four seconds wait four seconds and then make first bracket.
Then close that output semicolon.
So we have to use this.
It's called l return new wait for second so you can put the time over here.
And after that what you gonna do.
It's going to print out.
So let's suppose uh we're going to say something like after 0.12 second or a pretty short period, uh,
time, you can simply say, and after this amount of time that what we have to do, we need to disable
our line renderer right away.
So that's why we will go to LR, then enable and we're going to set equal to false.
Basically we just disabling this.
Firstly we age enabling.
As you can see we just going over to this line renderer component.
And then we just enabling.
And after this period of time here return you wait for second this period of time what we're doing we're
just going over to LR basically this line renderer component.
And then we just disabling it after just enabling this period of time.
And we're going to press down Ctrl S in order to save our script.
And now let's move over to unity.
Basically we want to see if it's perfectly working or not.
So in this start of the game we just disabling.
And once we click the left mouse button then we just enable link for short period of time.
So let's have a look.
So I'm going to click on this play button in the top in order to check it.
So I'm going to click the left mouse button in order to enabling that line renderer.
So I'm going to click the left mouse button.
As you can see, as soon as we click, it just gets active and some period of time it just gets disabled.
As you can see in the, in uh, in the scene view.
So we just enabling that.
And after some period of time we can see it's just getting disabled automatically because after that
0.12 seconds which is disabling.
So I'm going to get out of play mode.
And now let's move over to script.
And what we have to do.
We need to set the position so we can only see this line just getting over here active and just it's
getting the active, uh, after that amount of time and it just happening over here, instead of doing
that, what we're going to do, we're going to set the line renderer.
So we're going to store the first position over here.
And we're going to store the second position the ray hit width.
So let's suppose the ray hit with awe with this anime game object.
Then we're going to set the second position of the line renderer component where the ray hit width.
So let's go to script in order to do that.
So let's go to script.
And over here we're doing as you can see.
But before we do after enabling our line renderer component, we're going to set the position.
So we have to use this alert dot set position function and set position.
And first make this first bracket.
Then close it up with semicolon.
So this alert dot set position as a first argument.
Or it's going to take the index.
So we're going to pass zero zero basically means we just gonna refer the first position.
So we're going to store this position where the where we start our ray.
So we're gonna we shooting out our ray from this shoot point position.
So that's why we're going to store the first position in this index which is zero as you can see.
So the position we're going to pass through points position or where from which just shoot shooting
out the ray.
We definitely gonna shoot out the ray from this position which is our should point out position.
So we're going to pass our shoot point position or the first position into this zero index.
So the position is just going to be shoot point shoot point dot position and shoot point dot position
basically means where we shooting out the ray.
So we're just shooting out the ray from this shoot point dot position.
So that's why we just are taking our shoot point out position.
And we're storing in this zero index.
And we also need to set the second position as well.
So we're going to do it over here.
As you can see what we're doing.
We're just printing out a message in the console says takes damage.
So we also want to set the second position of that render line renderer component with our second index.
So we're going to do it over here.
So LR we're going to use this LR set position function in order to set the position and then make first
bracket.
So we're going to pass our index.
Now we're going to store our second position the ray hit width.
So the ray is just going to hit with this enemy game object.
So where hit width we can store that position in our one index.
So we just store it the first position in this zero index.
Now we're going to store our second position in the one index.
So firstly we're going to we have to type the index and then comma.
And we have to pass the position which position we want to store into this index.
So we're going to pass our hit info hit info dot point and then close that off with semicolon.
So hit info dot point basically means the ray hit with the position.
So the ray gonna hit with this enemy game object.
So so the hit point dot hit info dot point basically means the position the ray collided with.
So the ray is gonna collide with this, uh, enemy game object.
So we're storing that point or or where the ray hit with we just storing that position into this one
index, as you can see.
So we're going to press on control S in order to save our script.
And let's move to unity.
So we firstly we're storing our first position into this zero index.
And once the ray hit with then we're storing that uh, that uh or the second position which is storing
in this one index as you can see.
So let's move to unity now and let's click on this play button in the top in order to is able to see
that.
So once we click the left mouse button you will able to see the ray because we're storing the first
position into zero index.
So I'm going to click left mouse left mouse button.
As you can see as soon as we click we can see the ray.
Just uh, getting active with this or where the Ray hit with.
We're just getting to that point as well.
And I'm going to make the player speed a little bit slow, something like I'm gonna make, uh, in order
to check something like 0.5.
And let's click on this play button in the top in order to check it.
And I'm going to check one more time.
So I'm going to click left mouse button.
And we will see that, uh, the ray just gonna active or enabled for a few minutes.
And then it's gonna disable as you can see.
And we can see the ray just getting shoot it, shoot it out from that shoot point dot position.
And the ray just collided with this enemy game object.
So that's why the second position, uh, we just store it in the one index.
So I'm going to get out of play mode.
And let's suppose this enemy game object is not there.
So if I select my enemy GameObject in the hierarchy and I just disable it right away, go over to Inspector
and you can just uncheck that in order to disable.
And now if we click on this play button you will will not able to see the ray because the ray not are
not getting collided with that enemy game object.
So that's why we're not gonna able to see.
So if I just click the left mouse button, as you can see, it's just moving over to negative direction
or it's just shooting out from this position.
But we don't want to do that.
So I'm going to click on I'm gonna pause my game.
So what we want to do let's suppose if there is no enemy.
So we still want to see that line renderer or that ray and it's gonna shoot out with nothing and nothing.
So we just want to, uh, want to see or want to set a event.
It's just shooting nothing.
So we want to see in the right direction.
So let's get out of play mode.
So the if the ray is not colliding with that enemy game object, then we still want to see our ray.
So let's go to script.
And we're doing it over here.
As you can see if hit info basically means true means the ray is really colliding with that enemy game
object.
And let's suppose the array is not colliding with any game object, but we still want to see that line
renderer, and we're going to set the line renderer as the this as the length of the array.
So that's why we're going to use this else condition.
Else the array is not colliding with our enemy game object.
But we still want to set the position of that renderer component with the distance or the length of
the array.
So that's why we're going to use this else condition.
And we're going to check we're going to set the position which is LR dot position.
We need to use this function in order to set the position and close that off with semicolon.
So the array will not collide with anything.
So we're going to store the position in this one index comma.
And it's going to take the position where we want to set a set.
We do know that we're not going to collide with any enemy game object.
So we are gonna shoot in nothing.
But we still want to say see.
So that's why we're going to use this transformer, right?
Transform, right.
Dot.
Right.
Basically means, uh, in which direction we're shooting.
So we're just shooting in the right direction.
So that's why transport dot right.
Basically means the direction.
And we're going to multiply that direction with our length of the ray.
So we're going to multiply length or sorry we're going to use this distance basically distance.
Uh by default we set in Inspector ten.
And this is basically the length of the ray.
So we basically multiplying our uh direction with our distance.
So we're going to able to see the ray with the distance or the length of the ray which is ten by default.
We set in inspector.
And on top of that we're going to basically, uh, this will be direction.
So we're going to we add this, uh transform dot.
Right.
So we're going to add shoot point shoot point dot position.
And on top of that we're going to add this.
So shoot point dot position basically means where we shoot it out the way.
And on top of that, we're just adding our length of the ray, as you can see.
And we also taking the direction and we multiplying with this distance basically means the ray length
length of the ray.
So we the so this just going to be like this.
And we're just adding top of our shoot point top position.
So point dot position means where we shoot it out the ray and top of that we just adding the length
of the ray as you can see, because it's gonna shoot with nothing.
But we still want to say see the ray as the length of our ray.
So that's why we type.
Firstly we take taking the direction.
So we're going to shoot out in the right direction the ray.
And we just multiplying with our distance.
So we're gonna able to see our ray.
So this is the second position where uh when we're shooting in nothing which is storing this position
into this one index once the ray is not colliding with any enemy game object.
So let's press down control S in order to save our skip.
And now let's move over to unity.
But if you still are a little bit confused, then of course I will give a another video in the resources
about shooting out prey, and you can check that out if you just want to learn it more.
Firstly, what we're doing, we just taking our position from where we shoot it out, the way we just
shoot point dot position and on top of that we just taking the direction and we multiplying with the
length of the ray, which is distance.
So uh, so we're going to able to see our line renderer with the length of the ray which is ten.
By default we set and we just storing the second position for when we shoot in nothing into this one
index, as you can see.
And the first position we just store it in this zero index.
So we're going to press down Ctrl S to save our script and move to unity.
And let's click on this play button by now.
And you will able to see that as well.
So just wait for to compile and if we should nothing.
And then click left mouse button.
And now we are able to see our array.
As you can see.
And after 0.12 second it's just getting disabled automatically.
Let's get auto play mode.
And let me explain.
If we move to script, as you can see firstly we enabling our line renderer and then after we just disabling.
So we use this else return new wait for second.
And you have to put in this brackets the time in which uh after this amount of time it's going to be
disabled.
As you can see, after enabling and after this amount of time, we just disabling our line renderer
component LR dot enable equal to false basically means we just disabling and make sure you just call.
Basically we use this eye enumerator should function in order to delay some line of code.
So we need to use that.
So if you just want to delay any some certain things after some period of time, then you can use this
AI enumerator function.
In order to do that, instead of using void, we need to use this AI enumerator and you have to name
the function what we want to name it.
But before you include this function, make sure you just go to the top of your class and include this
namespace called using system dot collection.
And it's gonna allow us in order to use our enumerator function.
And you need to call function in a weird way.
Firstly you need to use this startcoroutine and you need to make this brackets.
And in this bracket you need to call the function.
In our case shoot as you can see.
So we're using this Startcoroutine and then shoot function.
And when we doing once we click our left mouse button as you can see.
So basically this is the cool thing.
And once once we shooting in nothing then we just taking our second position.
And we storing in this one More in this index, which is one or which is storing our second position
in this bond index.
But once the ray collides with that anime game object and hitpoint dot hit info dot point basically
means the ray hit with that enemy game object.
So we're just taking that position where the where our Ray hit with anime game object, we're just taking
that position and we're storing in this one index.
But once our ray is shooting nothing, then we just are taking our position with where we just were
shoot it out and we just taking the length of the ray and we're storing that whole thing or that position
in this one index.
As you can see.
I hope you get the idea that how you can do it and make sure you just press down Ctrl s in order to
save.
And let's suppose we just want to enable our enemy game object.
And I'm going to make our a our player jump a little bit high.
So I'm going to select my player game object in the hierarchy.
And I'm going to make the player script.
Or let's move to player script and I'm going to make the jump height something like 20 in order to check
or 25.
And I'm going to enable my enemy GameObject for now.
So let's select the enemy GameObject in the hierarchy and let's enable that.
And we will able to see by now.
So let's click on this play button in the top.
So once we shooting nothing the ray will still we will able to see our ray.
But once the ray collide with this enemy GameObject you will see the ray will be set.
Position the second position with this enemy GameObject where the ray collided with this enemy GameObject
and we can see.
And once we jump and shoot shoots in nothing, we still are gonna able to see our Ray or we just setting
the line renderer.
Uh, in our in nothing as you can see.
And our background seems a little bit weird, basically, uh, the parallax effect.
Then you can.
Then you have to adjust the perfect position.
And I'm gonna get out of play mode.
And we will select our player GameObject in the hierarchy.
Let's go to overrides and then click on this Apply All.
And I want to move this line render component in my player GameObject.
In the Inspector, I just want to move it up so we cannot do it over here.
Instead we need to open that in prefab mode.
So I'm going to click on this open in the Inspector.
And now what I'm going to do I'm going to right click on this line renderer component.
And I'm going to click on this pop up.
In order to move this component in top of this player, skip.
And if you just want to move it a little bit up, then you can just right click and then click on this
move up.
So it's gonna move up that component in top of the inspector.
And you're gonna able to see that.
And if you just want to go back in normal mode.
So in hierarchy you can see back arrow.
So just click there in order to go back.