Welcome back, My favorite game developers.
In this video, as you can see,
we have something a bit different.
We have waves, but these waves are not
just regular elements or regular variables.
They have the friend variables inside of them.
And we can create a another wave and another wave.
And as you can see, each one of
those has their own element.
So welcome to the Advanced C-sharp section.
Let's not waste any more time and let's get started.
But I need your full concentration,
your full attention span, and your fall.
Patients with me.
So let's get started.
Oh, okay, So now that we have our random levels,
it's time to create random NME waves.
So we're not just going to
have the regular enemies in here.
I just set them up in
the previous video so that we know what
the general idea is in
each level and just have
a bit of differences between them.
But in this video we are going
to create an enemy spawner.
So let's get started.
The first thing that we're going to do is
we're going to open up the managers.
And we don't have managers in here.
So we're going to go to one of
these that doesn't have a manager and this is it.
And what I'm going to do is I'm
going to go into the prefab.
We have a managers in here and I'm just going to add
the entire managers folder so we can
add managers to whichever scene that we need.
So I'm going to go into
the boss level that we have all the managers in here.
Yes, we do. The cowards.
We don't have the managers or
prefab managers and the managers in here. There we go.
Now we have the game level and all your manager.
And let's go back and see.
So the cowards, yes, save the health.
Do we have managers?
No, we don't.
So again, we go to the prefabs Prefabs Managers.
And there we go. We add the managers to the health room.
Let's go see what else do we have the new we have
managers top. We don't again.
So find the managers at this.
And if you want, you can just skip
this part and go straight to the,
you have in here.
But this is not the prefab,
so I'm going to delete this.
I'm going to add
the actual manager prefab
should have done this in a previous one.
Also scenes, what is this shop?
This Kelly's see, no manager.
And the managers.
And scenes spikes, save managers.
There we go. Boss level.
Managers that we want.
This is not the manager that you are looking for.
So cowards see?
Yes, yes.
Yes, yes, yes.
Okay, great.
So everywhere we do have managers
now it's time to actually create a spawner.
And the best place I believe to
start is in these Kelly's right here.
So in this case,
go to the level manager and let's go
ahead and add a component in here or no,
actually, let's go into the scripts.
And where shall we add the wave spawner?
And let's just add it inside of the managers
in here we're going to create a new C-sharp script,
which is going to be the wave spawner manager.
Hit Enter, we just added the Name Manager.
So again, we have an excuse to other top managers.
So I'm going to go ahead and add it to the level manager.
And in here I'm going to open up the script.
So what do we want to do in here?
We want to create another class.
Why do we want to create a another class?
Well, because first of all,
this is advanced C-sharp.
Second of all, we want to create
a entire different class for
the waves because the waves
have named the waves have enemies,
the waves has a balance of enemies,
the delay between each time we spawned an enemy,
and so on and so forth.
So in here, I'm going to go ahead
and create a public class.
And it's going to be called the wave.
And this wave will have a couple of things.
So first of all, it will have a public String name.
And obviously we don't want to have it always as public,
but in this case,
just so we can save a bit of time without
having to create all the extra things.
We're going to make them public.
Then we'll have a public game object
and an array of enemies.
What an array of enemies and me is. There we go.
Then we'll have a public and
the amount of enemies that will spawn.
And then finally, we'll have a public float spawn delay.
There we go. So these are all of the elements,
or let's say the part of the wave,
all the variables inside of the wave.
If you want to call that variable,
because this is a class,
it's something totally different.
But this is not the only thing that we need to do.
We also need to make sure to say that up here,
this is a system dot serializable.
So we save that.
And what does serializable mean?
It means that now if I open up
the Unity scripts right here,
you will see that.
Okay, nothing happened.
Why is that? Well, because we
also need to do one more thing.
And here we are going to say that this has a public wave.
As you can see now we have a totally new class,
an array of waves.
So we save that.
Now when we go back into Unity,
we shall see that we have the option to create waves.
And if I just add one wave in here,
you'll see that I have different elements for this wave.
And I can have an aim, can have an amount,
can have the spawn delay and the enemies that I want.
And if I add another element in here,
you'll notice that again,
I have a different name, different enemies,
different amounts, and different delays.
So as you can see, this is why recreated or made
sure that this is a system dot serializable.
This will allow us to create different elements of
this and will allow us to
create these types of variables.
So basically we've created
a new variable that has different variables inside of it.
So let's continue on now that we have all of this,
the next thing to do is to obviously go ahead
and start checking wave after wave.
So the first thing we need to do is in here we'll create
a private end and we will keep count of the next wave.
And obviously we will start at 0.
So the first wave will be 0.
And every single time we create
a new wave with a new amount of enemies,
with the new different types of enemies,
we will go to the next wave by increasing it by one.
Then we are going to create a serialized field where
we will keep track of the time between waves.
And let's just set it at five F as a default.
And then we are also going
to keep track of the wave count.
So float wave, I say wave count,
I meant count down.
Okay, save that.
And now when start we need to initialize
the wave countdown to be as the time between waves.
And then we are going to do
something for later on and was thinking,
but now we want to have something also as an extra.
And I think this is the perfect place to create
something of or something we've already covered,
which is an enum.
And why do we want to create an enum?
Because waves will be in three separate states,
we will have a spawning.
So this is where we are spawning every single,
I don't know the time or the delay between the enemies.
For example, every two seconds we spawn a new enemy.
We spawn a new enemy.
At this time, we don't want to be doing certain things
with our wave spawner controller or manager.
I mean, so we need to create different states.
So what I'm going to do is I'm
going to issue a challenge.
And your challenge is to create an enum
for the different states that we are going to have.
So we've already covered enums in the pickup section.
So first of all, create an E naught for
the different spawning states that will have,
will need to have the spawning, waiting and counting.
And finally, all you need to do is create a variable of
this type so we can use it as a reference.
So pause the video right now and go do each one.
Oh, okay, welcome back.
So as I've told you,
in one of the pickups,
whereas the pick-up pickup.
Pickup pickup, a bilayer?
Nope. Item dropper, dope.
Where was it? Where was it?
In the oh, okay.
So in the shop item as you can see,
we've created an enum for the health restore,
health upgrade and the weapon.
And based on each of those,
we have a switch statement.
We are going to do almost exactly the same thing.
So in here I'm going to create a private, private enum.
And this will be these pounding States.
And we are going to have the bombing,
the waiting, and the counting.
And then we'll just create
a variable of this type which is going to be
a private founding states and state.
There we go, save that.
And in here in the start,
what do we want to start with?
Well, we are going to start with the counting.
State is equal to spawning states dot counting.
So we start off by counting down and
then start also we need to make sure that we set.
Oh, so we've already said the wave countdown.
We want to update,
start counting down on the wave.
So if the wave countdown is less than or equal to 0,
then what we're going to do is we're going to check,
first of all, if
the state that we are currently in is different
than the spawning state, dot spawning.
Then what we're going to do is we'll start
spawning while the if
else we haven't finished the countdown,
then we are going to get the countdown and
remove for enrollment time, delta time.
So what is happening in here?
Let's just do a small recap
because all of this is fairly new.
First of all, we have the wave spawner manager,
which is attached to the level manager in here.
Okay.
Wait for this to compile any day now.
Okay, Thank you. So then what do we have?
We have a wave and
every single wave has different elements attached to it.
So what we decided to do is create
an entirely new public class just to represent it.
We could have if we want,
created a separate class just for this one,
in a separate script, just for this one,
and not have it be a mono behavior,
just a stem serializable and system
serializable means that allows
us to create this right here.
And it allows us to change
the different elements right here on how ever we want.
So it can give us the ability to
change the valuables much easier.
So we created the waves,
we keep track of the next wave that might be public
if you want just to make sure we see
everything appropriately, make it public.
We created the time between waves,
the waves come down.
This is pretty simple.
Then we created an enum for the spawning
States because we have different spawning states.
First of all, we can be either spawning,
waiting or we can be counting down.
And then we create one to just
keep track of everything happening,
just like we had in the shop item.
We will later on have different out should I say,
we will have different methods being
executed and the update based on whether we,
on which state we are in,
we will be having different elements, different things.
And this is the first example of it.
If we are counting down,
if we finish counting down
and we're not in a spawning state,
then we will start spawning.
If we haven't finished counting down,
we are just going to remove from the countdown the time,
delta time until it's under 0.
Then we check our responding.
If not, then we will start spawning in the next video,
where we actually will be spawning enemies.
So I hope you enjoy it.
I know this is a bit complicated,
but this is what you signed up for.
You came to the C-sharp advanced section in bonus one.
So I hope you enjoy it.
I hope you are committing your changes and I'll
see you in the next video.