Welcome back, my fellow game developers.
Look what we just created.
We run the game.
We will see one of the enemies in here.
And when we kill him,
we will go through doors.
And you can see that we have
the boss level and we have the health room.
So if I open the door,
I walked to the circle right here.
There we go.
I go to the health room.
I can pick up a health and I
can kill an enemy when he dies.
I have something different in here.
We will need obviously to
change everything on every single level.
But as you can see, now, everything works.
So let's not waste any more time and let's get started.
Okay. So you thought that I have left you, but I didn't.
I hope you did the challenge of creating
the actual appearing out of the name.
So let's go ahead and do just that.
First of all, I'm going to go into the door and here,
and I'm going to go ahead and add another box collider,
which is going to be the box collider 2D,
which is going to be a trigger and I'm going to
make it a little bit bigger.
So I'm going to make it yay big.
So it's right around the door.
And I'm going to go ahead and
apply the changes, applied changes.
Now we should see a box collider right here,
which is also a trigger.
Both of them are triggers.
And now I'm going to go to the door
or actually go into the scripts in here.
Make this a bit bigger
because we can barely see anything.
And where should we added any?
Let's go ahead and create a new folder for the door.
And then open it up and
create a new script that I'm going to
call the name fear.
Hit Enter for this to compile.
Today.
Now we will double-click in here,
open up the script,
and start typing a couple of things.
So the first thing we're going to do is
create a serialized field,
which is going to be text Mesh Pro,
so using TMP Pro.
So in here we're going to save the text.
Mesh.
Bro GUDDAT GUI is the level name UI.
And then we're going to create
a serialized field of the game object,
which is the level name Canvas.
And then we'll create a serialized field
which will hold the game object,
which is the door to open.
So we'll keep track of the door to open.
And why do we keep track of the doors open
even though I'm going to immediately add it to the door,
I can say transform dot SAT ACT or SAT non-active.
That's what we need to door.
But maybe we could add it in
a different place so I wanted to keep it right here.
So what are we doing?
Let's make this one,
the last one public and you'll know why and
just take it open door zone.
So this will make sure we can only
open when we are in the zone.
So when we start the game,
I'm going to say that the level name Canvas dots are
active as false because I never want to see it visible.
I'm going to create a method in
here that is a public void.
Set the level name,
which will take in a string variable,
which we'll call the level name.
And in here we're just going to say that
the level name dot txt, file name, UI.
There we go.
The text is equal to the level name that we were sent.
Then an update. What are we going to do?
We're going to say that if the input dot get key
down with a key code dot E.
And we are, and the open-door zone, Zen.
Zen, we are going Sue.
Okay.
An open door, the door to open, dot-dot-dot,
active to false. Save that.
Now the next thing we do is the on
Trigger Enter to D and the armed trigger exit to
the sugar exit to D.
And I'm going to check for
the parameter are actually for the collision.
So if the collision compare tag,
even though most probably we will say
that this can only interact with the player.
But I just want to take
my precautions just in case, just in case.
So in here are actually the door.
Does the door have any layer on it?
I don't think so. Not there is no layer,
so let's keep in mind the player.
So only the player can interact with this.
And what we're going to do is get the level name Canvas
dot set active to true.
And an open-door zone is equal to try.
And when we exit,
I'll copy this, paste it on a new set,
active, false, and we are no longer envy open-door zone.
So I believe this is everything.
I did it a bit fast,
so maybe I made a mistake somewhere.
Maybe we should.
Oh, there is one more thing that I want to do.
If for some reason,
let's say the player opens the door
and then he goes back and wants to open the second door.
I want to close this door again.
So whenever he leaves the zone,
I'm going to say that the door to open,
door to open thoughts,
Sad, active is true.
So save that. So maybe,
or maybe the player actually enters through
the door and then he cannot go
back once he is outside the area.
So this will mean that you
have to make a decision before you go through.
So with all of that out of the way,
I believe it's pretty simple.
There is nothing at all that might be complicated.
I'm going to go into the level of exit.
And instead of having all of this and start,
I'm going to go ahead
and right-click quick action and refactoring.
And I will extract the method.
And I'm going to say that this is the print name.
Apply.
And I'm going to remove from start,
we don't really need it anymore.
And also in here I'm going to say that there is
an integer that is being sent with the level index.
Why am I doing this?
Because you'll see in just a bit.
So the level to load would be equal to
the level and texts that has been sent.
So now what we can do is back and
the level manager in here
instead of Sunday level to load,
which is on the level of exit,
we can immediately print
room name and I can remove this method.
So print Exit, exit,
this public know it's private.
So I'm going to make public say that back in here.
And print room name.
Rent a room name, save that.
As you can see, this is a bit better,
a bit faster of handling things.
Let's save all of that.
We can actually remove the print, and instead,
we will need to go ahead and send it
to the name appear right here.
And let's first of all see
where we will add the name to appear.
Let's save that.
And let's see, we shall add it on the doors.
We'll add it to two or one.
And let's apply the changes.
So now under one we shall see
the everything that's lock it
down and add a couple of elements in here.
So the level, name,
weight, this is the text displayed,
this is the whole Canvas.
Then we have the level name as the text
Mesh Pro and the door to open,
which is the current one.
And in the open zone,
why did I make this public?
I still don't know. Let's go to the name
appear and thus remove the class, make it private.
I don't even remember why I decided to make public.
Maybe just to make sure that everything works.
Maybe, maybe that anyways,
and if I apply the changes,
we can see that in the door.
If I scroll down and
we have all of these option and it's actually
attached to the door 1 and
the text display is attached to the door one also,
which is very bad.
And everything will be at that.
So we need to do everything by hand in here.
So at the canvas,
at the level name
and it's going to oh, no, no, no, no, no.
That's because we have this lock down.
If I click on the actual door,
we shall see that I was so confused by this
because I know that when you
apply the changes on the door one,
you can see that only the door one
is attached, but the door 2,
you can see that the text is right here
and the level name is the one that is right here,
which is what we want.
So this is the amazing work of the prefabs.
And I was really confused for a second there
because I had this lock down and I clicked on the door.
It was the same.
Anyways, no worries about that.
Now that this is out of the way,
we will save this.
And now we need to somehow send,
or is it the level of exit we need to send
this name substring to the name appear.
So I'm going to say that in here we have
the serialized field of the game object.
The door.
And in here we have the name appear,
which we where do we have it?
Okay, so sublevel name. There we go.
So I'm going to remove these two parts.
And then say that the 0 door that Get component,
which is the name,
appear the set level name.
We'll close this down and now we
will have everything working.
Okay, so in here in the portal one,
I've assigned the door one.
So for some reason we have things a bit weird.
Maybe we can move the portal one right here,
and the portal right here,
I can just say,
but so portal one will have the door one as its door.
So port 1 and the door
1 and the normal portal will have the normal door.
We save all of that.
And now there is one more thing that
we need to take into consideration.
And this is something that I've thought about
all the way while creating this.
And that is we actually open the door immediately.
I don't know if you've noticed that.
Why is that?
Well, because if we go into the where is it?
One of the components in here,
which is the room, the room manager you can see in here.
If we double-click on the room manager,
you'll see that in the update
we have if enemy count is equal to 0,
then we will set all the doors to act it.
And the problem in here is that the enemies
are always 0 missing,
so the door is opened immediately.
So what I'm going to do in here is
just check to open Goldman enemies.
Are that no, not that.
I'm just going to remove this and we
can actually add this mechanic and to the game.
And maybe in the wave spawner
when we instantiate the enemies.
So when, when we spawned the enemies,
we can make them children of the room.
Where is it the enemies right here.
We can make them children of this enemies.
Then we can end the room manager.
Instead of just getting the enemies,
checking the overlaps, colliders,
sorry, in here and start.
We can do with an update every couple of seconds.
Then make sure that we don't open
the door or we don't check for
this until we go ahead and kill all the enemies.
This is all possible.
But for the sake of simplicity,
for the sake of just getting through this thing,
I'm just going to go into
the room manager and just comment this off,
save that back in our game, run the game.
And we should see now that the doors are all closed.
The level name right here and the level name or IT,
this is something that we do want to fix.
We don't want to be able to see what
the level is or having it be displayed on.
You can see right here that it's getting destroyed.
I'm going to shoot the enemy
and we'll see once he is killed.
So when he dies, now when I get,
you can see that now we have
the level boss and we have the shop.
I can open this up if I leave.
You can see that it does not close for some reason.
If I go right here,
I'll open this up, then go away.
It does not close. This is something that we will fix,
but anyway, this was the boss level.
Let's see if we go to the boss level.
There we go.
As you can see, we clearly go to the boss.
Love. How cool is that?
So now that the boss is that I'm going to, there we go.
So the boss dies.
We will wait for this to open up.
And obviously we need
to change a couple of things in here.
So first of all, the level name,
cool back in the year and the level of exit in
name appear in the start Canvas,
we are setting the whole canvas to false.
But then when we enter,
we are setting the canvas to true and we will
be fixing all of that maybe in the next video.
But the mechanics work,
the levels work, and I'll see you in the next one.
Make sure to commit all of your changes.