Hello guys.
Welcome to the video.
In this one we're going to work on the main menu.
We need to adapt it so it works for two players.
Let's go to main menu I'm going to save changes.
And over here we need to adjust the system a little bit.
First of all I think we should disable continue button because before we use continue button to go to
the last level player played, and there was a way to save information about skin he used.
But now since we can have two players, we never know which player used which skin.
Although we could save skin under like some sort of player one and player two variable, there is no
way of knowing who is going to be player one and player two in the next game, so it is better and easier
to allow player to choose skins every time they play.
And if that's the case, I think we just should make a play button.
And then every time somebody plays, he will do the entire setup from the start.
I think it will be easier.
Okay, let's go to main menu.
Let's disable continue button.
And on the main menu we did enable continue button with some.
A condition.
I don't remember the condition, but let me check.
Or is it?
Continue button.
If has level progression then enable continue button.
So I'm just going to.
Comment this out and let me take this hedge level progression method.
And I think it can be just there.
Let's leave it and I'm going to comment this out in case you want to use it.
Okay.
But I will not.
Now next step we need to go back to menu.
And we need to change text on this button from New Game to Play.
So let's just type play like that and we could take these two buttons.
Let me find it.
We can just drag them a bit higher like that.
And let me take the new game button I'm going to duplicate it.
Move it below and I'll just name it as quit button.
Yes.
And we're going to make functionality for it.
So you can, uh, quit the game from a menu.
Now let's take the play button.
Let's find navigation I'm going to change it to explicit.
And from new button we're going to go to Settings Up and no sorry settings down.
And quit.
Game up.
Let's change the order over here.
Yeah.
This one should say quit or exit.
We'd better.
And on a quit button.
We need to change navigation to explicit.
And let's do up settings down new game.
Let me double check the settings.
Up going to be new game and down going to be.
I quit just like that.
Okay, let me check this real quick.
Yeah.
Works good, I love it.
Let's change the name over here to a play game button.
And then let's go ahead to main menu and duplicate it.
I'm going to press Ctrl D to duplicate.
Then I want to disable main menu and this one should be layer mode UI.
Very nice.
Now, let's, uh, delete the quit button.
We need a back button in this UI.
So I'm going to copy this, paste it in and move it over here.
Now we have a back button.
And these two should be changed.
I can remove continue button.
And these two should be changed.
So this one's going to be one player mode button.
And this one should be.
Two player mode button.
Let's change the text.
One player.
And over here.
Two layers.
Very nice.
Let's check the navigation.
So this one goes up to back button down to two layers button.
This one is up to one layer button down to back button and back button.
Down to one player button and up to two player button.
Okay.
Two players.
Very good.
Now, this buttons supposed to set, uh, amount of players on a player manager, which we don't have
in this scene yet.
So let's go to asset prefabs.
Managers.
Player manager.
And we're going to go ahead here and.
Let's.
Make a method.
Public void.
Set up max players count and we're going to pass in max player count here.
And let's do a new player count.
New player count.
And then max player count is equals to new player count.
And also we need to take player input manager and ask it to set up maximum player count to new max player
count.
Just like that.
And then we can go to the wake and remove this line of code from here.
We don't need it anymore.
I'm going to remove it.
I'm going to save the script.
And then let's go back to unity.
In unity itself.
We need to take these two buttons and we need to add a method on click.
We're going to drag a player manager over here.
And we're going to choose player manager set up max player count.
Okay now for this one it should be one.
For this one it should be two.
Very good.
Also, let's make sure we switch into, uh, correct UI.
So these two are supposed to lead us to difficulty UI.
So I'm going to drag difficulty UI over here, then play game button.
Supposed to lead us to play mode UI.
So I'm going to drag player mode over here.
Other than that, I think it should be good on the player manager itself.
We need to disable joining enabled because otherwise you can create a player in the menu and we don't
want to do that.
So I'm going to disable this mark over here.
And.
This probably is good.
Uh oh.
Also on UI elements over here, we need to be sure we did drag player mode UI over here.
Okay, let's go ahead and try this.
I'm going to use my gamepad.
Play player one normal, you're going to select the player.
Level one there is me I can join and second player cannot join.
Very nice.
This is super good.
Now let's go back and let's try with two players.
I'm going to go back, then I'm going to go to play two players normal select level one.
I can draw in and second guy can join as well.
Very nice.
So it's working.
Uh, a couple of more things.
First of all, we want to make this.
Quit button.
Work.
Let's go to, uh, canvas.
Let's make a method.
I'm going to do.
Public.
Public void.
Quit.
Button.
And then over here.
We need to check something.
We're going to type if editor application is plain, which means we are in the play mode.
Then we're going to do editor application.
He's plane equals to false.
Else we're going to do application.
Dot quit and this will close the game if you are in the game in build, not in the unity editor.
Okay, now let's go back.
Let's take this quit button.
And we're going to change it from difficult to UI to main menu quit button.
Now let me try this.
And we stop the play mode.
Okay, last system I want to make in this video is a message that would say, press a button to join
the game right in the start.
Before you press the button for that, we need to go to player manager, and we need to make a list
of objects that we will disable once first player is joining.
So I'm going to do.
Sterilized field.
Private game object.
Array.
Objects to disable.
And then we want to go somewhere below.
Over here.
And I'm going to do for each.
VAR.
Game object.
In objects to disable, we're going to do GameObject.
Set active pulse.
We're going to need it later.
Also, we can change this wire to GameObject.
Doesn't really matter.
Let's save this and let's go to unity.
Now over here inside of UI.
In game we want to make UI text Mesh Pro.
This one going to be saying press to join.
Text.
And this one will say something like press any key to join.
Now let's change the font to Minecraft.
Let's make it bigger.
I need to find this text, and I think we need to increase the text size to something like this.
We need to attach it to the center of the screen.
Let's do alignment in the center and let's make this font really big.
Uh, something like this should work, I like it.
Now let's go to scripts of UI.
And over here.
I want to make a new one.
It's going to be UI text blink effect.
I'm sure there is a better word for it, but I'm going to use this one.
Let me open that script UI blink effect.
And first we want to know the duration of the cycle like during how long.
It will be transparent not transparent transparent like that.
So we're going to do serialized field private float cycle duration.
And then we want to get component of a text itself.
So I'm going to do private text mesh pro GUI text.
And let's open a wake.
Handle text equals to get component of a text mesh Pro.
Very nice.
Now let's make a method that will make it transparent or fully white.
I'm going to do private void toggle color and which we need to pass color.
And then we're going to do text dot color equals to color.
Very good.
And now we want to start a coroutine that will make this text blink.
And I'm going to show you a way to make an infinite loop the endless loop okay.
Let's do private ienumerator.
I'm going to do.
Blink.
Coroutine.
And then inside of this coroutine, first of all we want to get half cycle.
So I'm going to do float half cycle equals to cycle duration divided by two.
And then to make an infinite loop that will play all the time until you disable the game object, you
can do while true and then do functionality inside.
And this will basically work as an infinite loop.
So here we're going to do toggle color.
And we need transparent color.
I think we can just.
Do we need to set up transparent color though?
I remember the alpha.
So I'm going to do private color.
Transparent color equals to new color of 111..
Let's do point for alpha.
I maybe even point two.
Let's try that then.
Over here we're going to pass transparent color.
Then we're going to do yield return new wait four seconds of half cycle.
Then we're going to make.
Toggle color.
Coloured or white.
And then we're going to wait again for the half of the cycle.
And this will run an infinite loop that will make image blink all the time.
Let's go and start a coroutine in the wake.
Start coroutine of a blink coroutine.
Just like that.
And then we want to stop the coroutine when we disable the game object.
So I'll do on disable stop all coroutines.
Very nice.
Now let's go back.
And on a player manager, we have this array of game objects that we should disable once we start the
game.
What I'm worried about is that we may pass player manager from the main menu, and it will not have
this object to disable inside of this, uh, array over here.
So somehow we need to add this text to the array over here.
How could we do that?
I think we should turn it into a list.
Not array but list so we can dynamically change it.
And the list of game objects.
Like that.
And then we need to go to UI in game.
And in the start.
Start.
Where is the start method?
Why cannot.
Ah, there is a start method.
And over here I want to do something like GameObject.
Press join text equals to find first object by type of text.
Blink effect dot GameObject.
Then we're going to take player manager dot instance and objects to disable or not at least is private.
Uh, let's go back.
Let's just make it public.
Then we're going to go back to UI in game.
And we're going to do objects to disable ad press join text.
Okay.
So now every time we start a new scene, it will add this object of a blinking text to that list.
And then we will disable that game object once player presses the button.
Let's go and try this.
Should be fine.
Okay.
We just need to.
Take the component from UI folder.
And we need to drag it over here.
Like that cycle duration to text will be assigned automatically, so it should be good.
Let's go and try this.
And we have text being transparent and not transparent.
And I kind of like how it works.
If you want smooth change of the color from transparent to fully white, and then the opposite, then
you would have to do something like we did with the fade image.
But I think I'm going to keep this one because I like it.
All right.
And I press the button and text disappears.
Very good.
Now let me apply overrides.
And I'm going to go to main menu and I'm going to see.
The entire sequence all together.
Let's go.
Play.
Normal.
Select.
Press any key to join.
Okay.
Good, I love it.
And maybe we can adjust it a little bit.
UI text blink effect.
You know what we could do?
First of all, we could make it white, then transparent.
Like that.
All right.
So it will not become transparent immediately.
First it will be white.
Uh, let me double check that.
And I think we're good with this video.
We can go to next one.
Yeah, like on the old machines.
Very nice.
Okay, I'll see you in the next video.