Welcome back, my fellow game developers.
In this video, we don't do much,
but we do understand something or a series of methods and
dissections of strings that is very complicated but
extremely necessary for our case in order to continue on.
So let's not waste any more time and let's get started.
This is one of the more technical videos,
I believe, and the entire series on the entire course.
So I need your full concentration.
O k.
So now we have the waves being completed.
We have the levels or
the potential levels that we want to
go kind of being setup.
Now it's time to take it to the next level and get it,
take it the next level and actually
start displaying the names of
the levels that we can go to right here on the doors.
So what I'm going to do is
I'm going to go to the door one,
I'm going to right-click in here and I'm going
to create a UI canvas for this door.
So where's the UI canvas?
There we go, the canvas.
And if I open this up,
this will be the text display Canvas.
And if I go into this canvas and you
see what is the door have, okay, so, great.
And the canvas right here,
I'm going to select world space.
And I'm going to double-click to see the whole canvas.
We are going to scale it down to
0.001 on the x and on the y.
And I'm going to reset the position to be at 0, 0.
Now when we double-click, it's very small.
So we need to make
this one without a 0 and this one without a 0.
And or maybe do add a 0,
but make this one a2.
Oh, a five.
Yep, seems good.
And this 15, maybe we should make this bigger.
Let's make in an eight and this one.
And it also, yeah,
so I think it's pretty good, pretty solid.
So in here we are going to be adding
the texts that we will want to be displaying.
And what will this TextView displaying?
It will be displaying the level that you would be able to
go to once you open this particular door.
So I'm going to go ahead and apply the changes.
And when I do apply the changes to lower one,
you'll notice that the door to also has its own Canvas
now and all other subsequent doors
should also have these campuses.
So I'm going to keep working in here.
I'm going to right-click and the UI canvas and I'm
going to add a text Mesh Pro.
So a text Mesh Pro,
this will be the level name.
Hit Enter, and let's go ahead and make it a bit bigger.
Let's put it up here or you know what?
Let's put the level name under and
the duplicate this one and add it in here.
And this will simply read for us to open door.
And let's change the everything.
Well, everything that we're always doing, auto size, max,
level, color, and for some reason I cannot see it.
Why can I not see it?
Shouldn't be the level name,
this should be the open text enter.
What's the problem?
If I move it in here,
but it's not displaying and here.
And if I open the Canvas sorting layer,
set on the player,
so there we go.
So I've set the sorting layer to be on the layer
and because I have the front in here,
I'm going to just make it one to
make everything a little bit better.
Okay?
So I change the sorting layer of
the actual canvas right here
you can see I sell it onto player.
And I've been saying since the beginning,
we need to set new layers.
I haven't done that.
Maybe you did.
That's better.
You are progressing faster than me.
So press E to open the door.
And in here this will be the text level, level name.
And let's change this also.
Sell it to bold size, max.
And okay, great, So we'll save that.
We're going to go to the door and we're going
to apply the changes. And there we go.
So now you can see that this one also has
its own level name and press the E key to open the door.
So now what are we actually going to do?
We want to get the level name,
which should be a string and this plate right here.
But as you remember.
The level of exit,
where is it an exit?
We change this to an integer.
So how are we actually
going to do this in here and start?
I'm going to create the start.
And now you need to focus a lot,
but don't worry, everything will
be slowly but surely explained.
So first of all, I'm going to create a string
variable which is going to be the scene path.
And this path will be equal to seen utility.
Seen utility, but obviously we cannot use it.
So I'm going to add in here the senior management.
And now we should have access to the scene utility.
And then from the same utility I'm going to get seen
path can see right here by the build index.
So now I can add this right here,
and I can say the level to load.
Save that.
So what will this give us?
I'm just going to go ahead and print this out in here.
So I will say print out the scene path.
And let's just seen path concatenated. Save that.
And before I move on,
there is something that we
probably should have done and that is
actually using the level exit one and level exit to two,
assigned the level to go.
So level manager and where are the level exits?
Waves?
We have spawns 0,
so they aren't in here.
And I'm going to select the portals.
So portal has this one.
So which one has the first portal?
This one and the second portal will
be the second one on the level manager.
So there we go, we save that.
So now we have access to both the portals.
And now we can go back in here,
slide down and the level manager.
And after we get the level of exit,
one dot on the level exit,
we can either assign it immediately,
call this public, or we can
create a small method in here,
which we'll say that it's a public void.
And we'll make it set the level to load.
And this will be the level two load.
Or let's just make it level.
So shortcut it.
And in here we're just going to say that the level
to low level looped.
Save that back in
the level manager that set level to load.
And it's going to be the level 1.
And then in here we're going to set
the level x2 dot set level to low level to go to two.
Excellent.
So now we should have
this level to load being except right here.
And I'm just going to show you what
we are going to get displayed on the screen.
So when we run the game,
we should see right here in
the console, Let's pause that.
And the console we shall see
the scene path asset scenes style screen.
So obviously, this is the path that we
are getting sent and this is the current level to load.
And what does the current level that we're on?
It's currently being set as 0.
So 0, if we look in the settings in here,
you can see that 0 is the title screen,
so you can see how the scene path was being displayed.
So our goal is to remove everything and just keep
the title screen and have it being
displayed right here under the door name.
So that's what we're going to do.
If I go back in here,
let's remove the print.
And now this is the scary part.
I'm going to say that the integer is
the last slash and it's
equal to the scene path dot last index of.
And use this forward slash.
Actually it's between a single quotation.
So what happens in here?
Let's again print and, or know what.
Let's continue on and you'll
understand easily what that means.
So string name and
it's going to be equal to the same path
substring last slash and plus 1, 0 plus 1.
And let's try to print the name and see what we get.
So you can see the last index substring,
and then we are going to run this
again so we can see what's happening.
So we run the game
and we can see that we have right now the title screen.
So what is going on in here?
First of all, let's talk about the substring.
Let me just show you what that is.
Okay, so in here you can see
the string dot substring method and
definition and retrieves a substring from this instance.
And you can see we can use an int 32,
retrieves a substring, which will obviously a string.
Then we have a substring.
Substring starts at a specific character position
and continues to the end of that string.
So this is what's happening in here.
We are getting the last index
where we have this forward slash.
And then we are using a substring of that.
So remember how previously that would be displayed.
I'm going to print out
the scene path in here
again so you can clearly
see how the all of that is working.
Well, I'm taking my time to explain
everything because this is a bit confusing.
So on the console there we go, Assets, scenes,
and the last index where we have
this forward slash and then a title screen.
We have the last index,
which is the integer right here.
And then the name is a substring which
starts at the last slash plus one.
So we start immediately after
the visit right here after the last slash.
Now the final step is to remove also the dot.
So I'm going to do that.
And in here I'm going to say that int dot
is equal to name dot last index of.
And then I'm going to use the little dot.
And then finally I'm going to print out.
And probably you should do
this now that you know how everything is done.
Name dot substring.
And where is it between 0 and the dot.
And this is also another form of the substring.
You can see it right here,
a substring and 32 and 32.
So when we give it two parameters,
it retrieves a substring from this instance starts at
a specified character position and
has a specified length.
I'm going to go back in here.
I'm going to save all of
that and I'm going to run the game.
And they now run the game.
And you'll see in the console that we have,
first of all, we had the whole path,
then we reduced it.
And finally we have access to the title screen.
So as you can see,
this is very powerful and I will admit a bit complicated,
but this is the only way to actually do it for
actually the only way that I know
maybe there is another way,
but for now, it's time for a challenge.
And your challenge is to set
the text in a new script so make
the text appear and disappear if the player
is in a certain area next to the door,
get a new script and attach it to the UI object.
So obviously, you'll need to create a new script added
to the UI elements or UI canvas,
or maybe even the door if you want,
immediately added to the door,
use the entrepreneur enter and
exit similar to the shop items,
use the E key to open the doors and make
sure we can't see the canvas when we start the game.
So that information, pause the video right
now and go do VJ alone.
Okay, welcome back.
So this video is getting too long.
We are already about over 15 minutes into it,
and I don't want to make this a huge video,
so I'm going to cut it right now.
I hope you did the challenge.
In the next video, we will continue on with everything.
I hope you enjoy it. I'll see you in the next one.
Don't for the first time ever don't commit
your changes because we will
be doing a lot of things and the next one.
So see you then.