Hello guys.
Welcome to the video.
So in this one I want to finalize the UI.
We have I mean main menu and how buttons are working here.
We have a couple of options.
But overall it's all very simple.
We need to decide how are we going to do for example, new game difficulty, skin selection, level
selection or new game skin selection difficulty selection level selection order here is not very important.
So yeah, let's just do something here.
Uh, continue.
Button is already working as we need.
It just goes and chooses the.
The.
The level you should play.
I'm sorry.
I don't know what happened.
The only issue we need to fix is that you're supposed to continue on the same difficulty you had when
you left the game, so that's what we need to do.
All right.
We're going to take care of that in the end.
As of now let's go to new game button.
And new game will switch us to.
Now, let's say difficulty selection.
Then on the difficulty selection.
Once we choose the difficulty.
Next step would be to switch to skin selection.
So I'm going to select this three buttons.
And over here instead of going to the new game we're going to do UI.
Switch UI.
And as a UI we want to switch to it's going to be skin selection.
Then on the skin selection we have button select.
It will select the skin.
And we also want to go to next UI, but only if we select the skin, not if we buy it.
So probably we need to go to US skin selection.
And over here we need to make a method.
Or better, we can get a reference to the.
Now level selection and just enable level selection through UI.
Main menu.
So how are we going to do this?
We have this method switch UI and it's public.
So on the skin selection we can do private.
UI level selection.
Level selection UI.
And we need private UI.
Main menu.
Main menu UI.
Now in the start we're going to do main menu UI equals to get component in parent of UI.
Main menu.
And then we need to get level selection UI, but it is not apparent and if we don't want to assign it
manually, we can do something like this.
Level selection UI equals to main menu UI.
Get component in children of UI level selection.
This is how it will be.
And then.
On the select skin over here only if we select in the skin, we're going to do.
Um.
Main menu UI.
Switch UI.
Level selection UI.
And actually I just realized it should be GameObject variable over here.
Or we can do in opposite.
We can just go here and do dot GameObject.
Okay, now let's save this.
Let's go back.
We don't need to change anything on, uh, this select button, because we're doing it in the script.
And this will switch us to level selection.
And then on the level selection we're going to have buttons that will run the level.
So basically it's all ready to go.
Let's try this.
I have a new game.
I'm going to click.
New game.
I want to choose difficulty.
And.
Okay.
This is good, I found it.
Let's fix it.
We need to go to main menu.
No.
Sorry.
Canvas.
And we need to add other UI here.
So difficulty goes here.
And do we have anything else?
12345.
Okay.
This should be good.
Let me try again.
New game normal.
Select the skin.
I want to purchase this one, then I want to select it.
And we have a error.
Level selection UI.
I guess we did not get the component.
Why not?
There is a level selection UI.
It is a child of a canvas.
So.
Oh man, I know why I'm here.
I got it, okay?
It's good, I got it.
All right, so this is what is happening now.
Let me go to skin selection.
We can switch it back to what it was with, um, main menu UI over here.
Becsehely.
Basically, it's the same thing.
Doesn't matter, but let's switch it back.
So what happens here?
We're getting component.
And if component is disabled, if GameObject is disabled you will not be able to get it like that.
You actually need to type true over here.
So it will consider disabled gameobjects as well.
And now if we do it like that, it's going to work all right.
Pretty nice.
I completely forgot about this.
Can you imagine?
Let's go to play mode now.
New game.
Normal.
Uh, let's select this skin.
We are on the level selection.
I'm going to click level two and boom!
We are in the game and I can play and enjoy the game.
And difficulty is normal okay.
The only goal is now to pass last difficulty.
We used to continue button because as of now if I click continue I'm going to be playing easy mode.
That's a bug.
Now over here on difficulty.
Manager.
We're supposed to be able to choose difficulty with the integer, because we can save only a float int
and string.
We want to save int to know the difficulty index.
And then we can just set it with a method.
So how it's going to be we have this as easy at zero, normal at one and hard at two.
But if you would like you can start count from one.
For example you can do equals to one here and now this will be one, two, three.
So just as a you know like different example, let's try to start from one.
Why not.
Because zero calendar says like we have none.
So we cannot use zero, one, two.
I guess that would not be very logical in my opinion.
So.
Yeah.
Uh, when we.
When we go into the game from a level button over here, we want to save the difficulty.
You mean exactly when we choosing the level only then.
Because if we choose difficulty in the middle of the UI, then go back, then it can forget what difficulty
was there.
So I guess it's better to do it here on a load level.
So you're going to do Playerprefs set int.
Game difficulty.
And here we just need to take enum from a difficulty manager and turn it into integer so we can do.
Int difficulty index equals to difficulty manager.
Dot instance dot difficulty.
And then we just type.int and it will convert it to integer.
And we can pass it here difficulty index.
Very nice.
Now let's just copy this line of code.
Let's go to the main menu.
Over here we have continue game.
And I'm just going to.
Do int.
Difficulty index equals to Playerprefs.
Get integer.
And we're not going to pass default value.
I think a better let's pass one just in case, you know, just in case.
Okay.
And then before we, uh, load the level we want to call method on a difficulty manager, give it an
index and that will choose difficulty for us.
So let's go here.
Let's do public void load difficulty.
We're going to pass int difficulty index.
And then over here I'm going to do difficulty equals to.
And we're going to type and we're going to open parentheses type difficulty type and then difficulty
index like that.
And it's going to switch it uh over here it's going to choose the enum by the number over here okay.
So it's sort of like converting it back okay.
So we have a method.
Now we can go to level button.
Oh sorry.
Main menu.
Continue game over here.
And then we're going to do difficulty manager.
Difficulty manager dot instance dot load difficulty.
And we're going to pass it difficulty index okay let me try this.
I'm going to save it.
And then we're going to go back to unity.
Go to play mode.
I'm going to do a new game.
New game Hard mode.
Let me choose the guy.
Play level three and now we saved the difficulty.
I can go and die, for example.
Then I can exit play mode.
Go to play mode.
And we can click continue.
And it's going to be hard over here.
Okay.
Very cool I like it.
Uh, let's switch it to easy by default.
All right.
I'm going to save it now.
Game is basically playable.
You can make more levels.
You can test levels.
There are many different things you could do.
But don't rush yet.
We still have to do, um, sound effects.
Also, I want to do a bit of polish and there are some other things, but probably you can just see
them, you know, in the sections list on the course.
Okay, I'll see you in the next video.