Welcome back my fellow game developers to a brand new video.
As you can see, we've added a couple of rooms to our game.
We've added a couple of paths to our game now our level,
or actually I should have said our level.
Now our level looks kind of really nice.
You know that Cinna machine really did add some flavor to the game,
which gave us the ability to run around and make bigger levels and more interesting ones.
But that's not the only thing that is very cool.
If I run the game, look at the scene,
you can see that now we have doors that are blocking our way from moving.
And these will be the doors that we used to go to
the next level after we kill our enemies,
obviously we need to kill our enemies.
But this is not of our concern right now.
Later on it will be.
But for now, let's not waste any more time and let's get started.
And we will be learning full of amazing stuff, amazing 0 case.
So we are going to go ahead and create doors.
What are the doors?
I've created the door's already,
you can see them right here.
I'll provide you the door and the resources,
but it's fairly simple.
All I did was cropped out the where is it?
The main photo?
The main picture.
And just use the door that was already available there.
So now we can go ahead and add the door or let's add it in here.
So we have the door,
we set the layer maybe on the player or we can set the layer on the, on a separate door.
And what those doors is going to do is it's going to go ahead and close
these two pathways that I've also created and I haven't talked about those.
So what is the point of our game?
How are we going to transition from level to level?
Just like we saw in the hades game.
Every time we kill all the enemies,
we will have these two barricades.
We will have this door and a second one.
So here two doors.
And when we kill all the enemies,
we are simply going to deactivate the doors.
And this will allow our player to move through and to the pathway where
he will find two portals here and he can go through them.
But let's not get ahead of ourselves.
Let's first of all start off by making sure that
these doors work and what else wanted to tell you? Oh, okay.
So if you go into that tile palette right here,
you can see that we can add these two anchors or wherever you, these pathways here.
But the problem with these pathways,
if I click on the grid and wall,
you can see that they will also stop the player from moving.
So what do I mean?
I've made sure that this is the ground and these are the wall.
And if I, for example,
run the game, you'll see that I can walk around everywhere.
And if I go through here,
you can see that I can no longer move.
And that's because we have a collider under and that is
something that we will have to fix in order to move through them, obviously.
So how are we going to fix this?
Well, if we go into our tile set right here,
the cones, if we scroll down,
we can find the image right here.
Go into the inspector,
select the Sprite Editor.
Open this up.
If we go from the Sprite Editor to the custom physics shape,
Let's click in here.
You can see that if we, Where is it, ok,
so the anchor and here,
if we click on one of those, we can generate.
And now we have the anchor points of the physics.
So this is how the collider will be rendered on this sprite.
So I'm going to make sure that it's very or not even tiny.
I'll make sure that it is about 0.
So asset this like this, like this,
and finally, lie this.
I will apply the changes and wait for just a second.
It will take a bit of time to change the colliders and the game Also,
we might have to draw these price again.
Okay, great, So this one is finished.
Let's generate on this block.
Also. Move it here.
We don't need to move it down like the one in the middle.
We can just move it to the right.
Apply. Now the collider will only be on this side.
And finally, find any, any day.
Now, we can click on the last one,
generate OK. Not last one.
Actually, we still have two more to do.
So.
Now that you know how this is done,
I'm going to do the one above and I'm wound to
obviously expect you to be doing this at the same time with me.
This is not a challenge.
This is just us making our game much better.
So generate, generate, move this to the left,
I apply the changes.
And for some reason it is extremely slow.
I thought it might be just a little bit faster.
So come on, Generate.
Move this here.
It's like that, just like that.
Apply.
And I'm so excited to show you how this is all going to work.
Final one, generate how boring is this?
Yep, it is.
I know it's because of the waiting time that we have to wait
for unity to generate physics.
So I think we should have moved this down also.
Let me just see something also should have been moved down.
Just like that. Now we apply the changes.
Now if we go back,
maybe we should draw them back. Maybe we shouldn't.
That's the problem with limited.
If we go close when it unity than open it,
maybe we won't find this problem.
So let's see what we have.
So there you go, the walls are still there,
but if I choose this another time,
and I draw that, Let's say here.
Okay, So obviously there is something very wrong here.
Oh, okay, so we had a small technical problem.
Now if I click on the walls,
I thought for a secondary didn't work, but it did.
Now if you see the walls,
the collider is no longer here and just on the sides that it's intended to be on.
Now when I run the game, I look here.
If I move up, there you go.
I can walk through them.
Now, obviously there is a problem which is that I'm walking over them.
We will fix this in just a bit,
but for now we have this working.
This should maybe be on a different layer.
No worries about that. Let's continue on.
What do we actually need to do in here?
And we need to add the two closed doors.
We need to get a reference to them and we need to make sure
that whenever the player is in the room,
we want to close them off.
So let's get started.
The first thing that we want to do is we want to go ahead and add the two doors.
So I'm going to go into the doors and I'm going to select in the inspector in here.
And I'm just going to add it in the hierarchy,
create the object first Gore fits here.
I'm going to go ahead and set it as the Charlotte set it as the player.
No worries about that.
We'll set that as the layer, layer.
So this is the door one,
and I'm going to duplicate it.
This is going to be the door 2 and I'm going to move it to the other side.
Or you know what, let's not duplicate this right now.
First we need to add a box collider around
because we don't want to play or to move through this door.
So I'm going to add a box collider 2D.
And let's see how that box looks.
Okay, I think that looks good enough.
And I'm now going to duplicate this door.
This will be the door 2,
and I'm going to move it right into here.
So now these two pathways are closed off.
I will run the game.
I will try to walk through the door and there you go.
You can see that I cannot walk through.
Excellent.
Now, what is the next step?
The next step is I'm going to prefab this.
I'm going to go into the prefab, right-click.
Create Folder, room, or rooms or wrong.
This will be for anything that involves a room.
And I'm going to just prefab this and I'll call this the simply the door. There you go.
And now I will just add this again at the prefabs.
So it's attached to the prefab.
So if we ever change something,
that changes are happening for everything.
Okay, so let's go ahead now and create a game object in here,
which is going to be called the room.
I'm going to reset its position.
And this room will have a child on it called the doors.
And this will be the object that will hold all the doors that we have in the room.
Now we are going to create a new script in here.
And we're going to attach it to the room,
and this will be the room manager.
So scripts, right-click, let's create a folder for the managers.
And in here we are going to create a C-sharp script for the room.
Manager.
Hit Enter, wait for it to compile.
No, thank you.
I don't need it right now.
And wait for it to compile.
Okay, So rooms, Let's add the script in here.
Let's open up the room manager.
And what do we need in here?
Well, we need to have an,
an array of game objects that will represent the doors that we want to close.
So the game object and array,
which is the doors to close.
Save that.
And now what we want to do is we want to create a huge trigger around the entire map.
And then check when the player is inside this trigger room.
And why do we need to be inside the sugar room?
Because maybe.
For example, you want your game to have just a little bit of a bigger level.
Maybe when you get through some kind of doors,
the doors close and then the level starts and until you kill all the enemies,
then you can move out of the room.
So that's why I wanted to go with
this stop process of having doors close only when the player is inside the throne.
So let's first of all add these two doors on
coming to lock this down at the two doors to the doors to close.
There we go, save that.
And now I'm going to go back and my script.
And in here I'm going to create a boolean which will be a serialized field.
And that will be the close door on layer.
Enter.
Save that.
And what are we going to do in here while we are going to go
through all of these on the, on sugar.
Enter.
Okay, this should have been too deep.
And actually let's create the entrepreneur enter to the immediately.
And in here we are going to check if the
collision.com tag is the layer.
Now I'm going to cheat because I already know how player is written.
And we are going to check if closed-door on player enter.
Okay, So now we want to go ahead and close our doors.
Now we have this array right here.
What should we do?
Should we go through all of them and close them one by one?
So I should write door to close, for example,
0 dot active to true,
and then do door one,
door to door three.
We could do that, but there is a problem and we don't know how many doors we will have.
So what we can do is we can loop through them.
And one of the first full or the first loops
that I want to teach you is the for each loop.
So what is a for each loop?
Let's see how that structure works.
It allows you to go through each thing in
a collection of things of the same type in an array.
So what do I mean by things?
So let's say we have a type which in our case is the game object.
The thing is the door in the doors that we want to close.
So what we do, just like it says, for each door,
which is of type game object in the doors to close,
we can go ahead and do stuff with it.
So for example, we can access some method on the thing.
We can use the thing in some other method and we can execute other things.
So was that explained what we want to do?
Our goal in this video is to go ahead and access or loop through using the For Each,
we want to loop through all the doors and make sure
that we set all of them active to true.
So as soon as the player enters the room,
everything will be closed off until he kills all of the enemies later on.
So with that explained,
I am going to issue you a challenge to go through all the doors and close them.
So create a for each loop that goes through all the doors endorsed closed.
Set, each door to active.
And I'll just give you a hint.
Use the set active to true.
I've already showed you.
I tried to give you as many hands as possible.
I know this is maybe the first time you see loops.
This is a great opportunity to try to see something for
the first time and tried to implement it in front of you
without me teaching you that beforehand.
I know it's a bit hard.
I would drink it as one of the hardest challenges,
but don't worry about it.
Take your time. Pause the video,
try to do your best and I'll see you in just a bit.
K, How did you get all of that?
I hope it wasn't too hard.
So what we're going to do is we're going to create a for-each loop.
And as I've said, we are going to go through the game objects.
And we can call this whatever we want the doors,
the doors we can call it ABC you whatever we want in doors to close.
And what we'll do in here is we'll simply access the door,
dot set active. True.
Save that.
Back in Unity.
We are going to go ahead and activate these doors.
So let's say they are open.
First thing we enter the room.
Okay, Also, I should not have clicked on here.
I'm going to turn on back the room.
So what happened here?
And that's something that I always fall to
as I've had the room and I've had it locked in.
So I chose the two doors and clicked on this one.
So I turned off the room.
Actually, you can see right here whatever you choose,
it's still the room.
So what I'm going to unlock this shows the two doors.
And I'm going to.
Go ahead and turn them off.
I'll go into the room.
I'm going to add a component which will be a huge box collider.
Now, the only problem here is that maybe the collider will check
for the player and when he actually hasn't yet entered the room.
So let's go back in here and see on Trigger Enter.
When we enter the trigger,
that's when this method will be called.
So let's see.
I'm not sure, sometimes it's because of how the script is executed.
So FVA room script executed first,
then we will have the room,
and then we will have the player.
So this way the player actually enters.
So I'm going to save this.
I'm going to, okay,
so this is a trigger when I have an error.
Okay, so this error is nothing to worry about.
Run the game.
Okay, So the doors didn't close.
Let's choose to close the doors on player enter.
Okay, So there we go.
It worked. So I hope you understood what my concern was.
I sometimes this is what happens when I was first creating this game.
This is what happens.
So I had to create something different.
But I noticed that sometimes it works, sometimes it doesn't.
I just wanted to let you know beforehand so you don't think Oh,
Michael, every single time a mistake.
Now actually, so I hope you enjoy it.
I hope you did the for each challenge.
I know it was a complicated,
but this is a good way to practice your game developer skills.
So I'll see you in the next video where we will be catching
all the enemies that we have so we can kill them and then open the doors when they die.
So I'll see you then.
Make sure to stage all your files.
Sorry for that.
And make sure to leave me a review if you haven't yet.
It helps me out a lot.
Thank you.
See you next time. Hey, Michael here from the future,
you thought you got rid of me, but you haven't.
When we run the game,
I noticed something that you can see that I was
wondering why the skeleton wasn't shooting us and if I tried to shoot,
you can see that immediately.
I have the bullet Impact effect.
What's the problem here?
Well, because we are sitting inside of the room collider,
we are shooting and it's immediately interacting with it.
So the problem here is obviously it's the layers.
So what we want to do is we are going to add a layer.
We can call this the untouchables or whatever you wanna call it.
I'll just call it the room layer.
Hit Enter.
And I'm going to go into the matrix and here project settings.
And I'll make sure that the room layer doesn't interact
with the other room layers with the enemy bullets.
And maybe we can even make sure that they don't interact with anything.
Honestly, we don't need them except for the player.
We want to go ahead.
But for now, let's just make sure they don't interact with
the bullets literature on if we do find a problem,
this could be problematic and know what.
Just for that reason,
let's turn everything off, save that.
Closed down from the game.
The good doors should close.
And if we shoot, something is still wrong.
Oh, obviously we need to set it as the room layer yes.
Changed children if you want to run the game or no,
maybe the children shouldn't have been changed.
Okay. So the door closes and we can shoot normally.
Maybe the children shouldn't have been changed
because I don't want the doors to be affected.
Let's change this to default. Yes.
Changed children. Okay. So now we can shoot the doors,
but we can shoot around should the walls, should the doors.
Yep. Everything is working fine.
So from the future, I'm leaving.
See you in the future future.