Welcome back, My favorite game developers.
In this video, we are actually going to be
completing the wave, starting new waves.
Once we finish all of them,
we have the option to open the doors.
Don't open them yet, but we will.
Unfortunately, because this might take a lot of fun.
I'm not going to demonstrate it in the intro,
but feel free to watch the video.
You will see that it is actually working.
We made sure that it does.
We always make sure that it does.
Okay. So I think we are at a good point.
So as you can see,
you sought to enemies randomly spawning.
The time has finished. Let me okay.
So the spine on the same position we call them,
we should see in the Inspector that
we've completed all the waves,
which means we will open the doors.
So let's not waste any more time and let's get started.
Oh, okay.
So what is happening right now?
First of all, I forgot to stage all of my files.
I'm going to call it an instantiate,
various types of enemies.
This was the previous video,
but now let's focus on what's happening in yield.
So you remember that in the last one,
we actually started completing waves,
but not White so
much because even though we finished a wave,
you might have noticed that Then again,
and it means start spawning.
Why is that?
Well, that's because obviously
the wave countdown is still less than 0.
We are going back to spawning.
And well, obviously, sorry,
we are not going back to spawning,
so we are always starting with co-routine again.
So what do we need?
Do we need to actually,
first of all start a new wave?
And second of all, we need to
reset all of that and make sure
that at the end we stop the all the waves.
We've finished all the waves.
We can open the door and so on.
Man. Not only that,
we also in this video,
we want to create several points
from which the enemies will be spawning.
So we have our hands full.
Let's not waste any more time.
What should we be doing in here?
First of all, I'm going to scroll down and create
a new void, Start New Wave.
And what happened?
And in here I'm going to say that as
soon as we want to start a new wave,
then we are going to set the state to
the spawning states that counting.
So in here we are counting for the next wave and
the wave countdown will
be equal to the time between waves.
Folks, not enemy search the time between waves.
And then in here we're going to check
if the next wave plus
1 is equal to the waves got length.
So that means that we are on the last way,
that the next wave as the last one.
Then we're going to say that debug dot log.
And in here we'll say we've completed all the waves.
And I just said something I believe,
isn't that true in here?
First of all, we need to add two equals,
equals to compare when we add one equal,
that means we are assigning
two equals as when we comparing.
And I said in here that the next wave is the last one.
No, When I said next week plus 1 equals wave that length,
that means that the next wave right here
without the plus one as the last index.
So next wave plus 1 is the size of the entire array,
which is the waves dot length.
So that means that we are currently on the last one,
which means that debug dot log
says we've completed all the waves.
And we'll just add a comment here.
We can open the doors,
open doors, get rewards, etc.
Okay, And then once we finish,
so if we're not on the last wave,
what are we going to do?
Well, we're going to say that the next wave, plus, plus,
so plus, plus, so we increased the next week by one.
So now all we got to do is when we check for
the enemies and update and the wave is complete,
we are going to start a new waived.
So I believe that's all that we need to do.
So I'm going to go back into
my game in here and I'm going
to say any day now, please.
So in the level manager, let's see,
we have let's make sure that we don't have any problems.
I'm going to change this to the,
where are the enemies?
Let's make it smaller or are the enemy prefabs, enemy?
Okay, so we have the petroleum,
let's make sure that
the first wave only has a skeleton enemies.
And we'll create a second wave in here, which is the,
let's just call it high wave because we have
the flying eyes and we are going to have both.
Of these be the cowardly.
So we will know when we are in the next wave.
So I'm going to save all of that.
I'm going to check in here,
okay, time between waves.
Let's run the game and see how that looks.
So I'm going to run
the game and we should only see skeletons.
Skeleton, there we go.
So now when we kill them,
we should only see flying crows after the five seconds.
There we go, The Flying crow,
you can see it from behind these two,
and they killed me,
but everything seems to be working perfectly fine.
As you can see, we are resetting the time.
If we scroll down.
If you didn't completely understand what's happening,
let me just redo it once.
So as soon as we start a new wave,
we start counting down until we get to the next wave.
Then the wave countdown is reset to
the time between waves. So an update.
And here we are going to
remove Time.deltaTime every single frame,
which means that we are starting the new wave.
Then we check, are we on the last wave?
If we are, that means we've
completed all the waves and we can open the door.
Unfortunately, our enemies killed
us before we had the chance to do so.
But before we actually test this
out and make sure that
it's working this condition right here.
Let's first of all,
create several points from which the enemies can spawn.
Because as you can see, we don't really like having
all the enemies mashed up together
and 1 and having them small.
We want to have some kind of diversity.
So for that, what I'm going to do is I'm going to issue
a challenge to create spawn points for enemies.
First of all, you need to create an array to spawn bonds.
So this spawn points,
this should be of type transform this array.
Then you'll need to create the points in
unity and add them to the inspector,
obviously on the level manager.
Finally, when we spawned an enemy,
choose a random spawn points and put them there.
So I'm going to tell you to pause the video
because for some reason
my punk isn't just working correctly.
So I'll see you in just a bit.
Hey, welcome back.
So how did you get on with that?
Then if I scroll up here and I create
a serialized field of transform,
which becomes an array of the spawn points.
Save that. And then I scroll down to the,
let's see what we have in here.
Oh, so where are responding the enemies right here,
we can simply remove the debug.
He didn't even use it once.
So in here, what shall we do?
Well, we shall first of all,
create a transform of obviously a variable of type
transform the transform on
the game object for this power point.
And hopefully this will be the last video
where I have to say the word spawn,
spawn, whatever it is.
So between these points,
and in here I'm going to say random range
between 0 and the spawn points about length.
So we are choosing a random spawn point.
And in here, instead of using
the transform of the game object,
we'll use the spawn point
that the random spawn point that we got.
So I believe it's pretty easy if you
didn't understand what's happening in here.
We created obviously the spawn points that
we'll be adding a new unity in just a bit.
Then when we instantiate an enemy beforehand,
we use to immediately put him
on the level manager game object.
We said that we don't want to do that.
So what we do instead is we
use the transform box bomb point.
We create a random one
using the array that we have up there,
using a random dot range from
0 to this point, points dot length.
And then we set the enemy,
we instantiate them and respond point documentation.
We save that. We go back into Unity.
I'm going to create all this bond point
under the level manager,
since he's handling all of the spawning source points.
And I'm going to create an empty spawn point, 1, 2, 3.
So I will have three spawn points.
Let's make the scene a bit bigger.
And in here, Let's see,
the first one will be here,
the second one will be here,
and the third one will be in here.
So save all of that back in level manager.
Let's see what we have in here, the spawn points.
Let's, oops, Let's lock this down.
Let's drag, Sorry.
Let's drag the spawn points right here.
We say, well, that we run the game.
And now we should see as we are looking,
so 321, There we go.
So we spawned one here.
Then after two seconds, one is up there.
So I'm going to try to kill all of them.
And let's see the second wave.
That wave come down.
Then we get one enemy which is up here,
a second enemy which is down here.
And then I'll try to kill them using and
the view on the scene so I
can catch them from a very far distance.
So the current, the enemy dies.
And now we have a count down.
We can see right here that
all the waves have been completed.
If we double-click, where is it?
It's right here where we are going to
be opening the doors obviously.
And the next video and creating also portals
that will take us to another dimension.
Actually it's just another level.
But anyways, you get the point.
Let's stop the game.
But stop unity.
Make sure to commit our changes.
And I'm going to call this the, the,
now we actually complete Waves.
We start commit those changes.
And I'll see you in the next one.
And if you're enjoying,
this is above the end of the course.
Make sure to leave a review at helping out a lot.
And I'll see you interested in.