Hello guys.
Welcome to the video.
In this one we need to adapt skin selection for two players so you can choose skin for the first player
and for the second one it's going to be not that difficult to do.
Just takes a bit of a time.
And I think we can start right now.
So we need to go to the main menu scene.
And then we need to find this kin selection.
And I want to explain how it's going to work.
So I need this menu character animator.
Layers.
And then we need skin selection.
Okay.
So look, as of now we have skin index number that cannot be bigger than max index.
And then we switch it from minimum to maximum or an opposite.
And then with this number we choose layer on the animator.
And at the same time we send same number to the skin manager.
This is what we do now instead of this I want to have a list of numbers so we can find an element,
check which skin ID that element has and then choose skin from that because we cannot just leave it
as it is right now.
We need to be able to remove one of the skins from the list when it is already chosen by player, because
we don't want players to have two same skins, right?
Uh, this is how it's going to be.
We're going to go to us skin selection, and I'm going to do a little bit of a change here.
Uh, we're going to make a header.
UI skin details, maybe like that.
Then I want to take skin index.
Move it here.
And we're going to rename it to Current Skin Index.
After that we're going to need serialized field list of integers.
And we're going to name it as skin index.
Then we don't need the max index anymore because we're going to use skin index dot count as a maximum
value.
So I'm going to remove it from here okay.
Very nice.
Now let's go down to the next skin and previous skin and change method slightly.
Uh, we're going to go here.
So instead of using max index, we're going to use, um skin index dot count.
And we need to do minus one here.
Then over here we need to do.
In index.
Dot count minus one.
We do minus one because if we have four elements in the list, then last element would have number three,
not four.
And if we want to choose the last one which is supposed to be three, then we need to do minus one.
All right.
So this half of the job here then let's go to update skin display.
And over here I want to make an integer int nu skin index, which will be equals to.
Skin index with a current skin index just like that.
Uh, maybe let's rename this to Selected skin index.
Now over here.
Oh.
I'm sorry, what was that?
What was that?
Then over here, instead of current skin index that we used before, we need to use selected skin index.
If it doesn't make sense, just wait a bit.
I'm going to show it to you in unity and you'll understand it.
So we're using it here.
And also now we need to check if skin list with the selected skin index is unlocked.
And then over here we need to choose selected skin index like that.
Very good.
Now let's save everything.
Let's go back to unity.
Over here.
We can see we've got a list of indexes.
Let's make size four and we have first, second, third and fourth element with the index of 01234.
So this one's going to be zero.
This one's going to be one.
This one's going to be two.
This one's going to be three.
And this is how it is before we just took a number to choose a layer on the animator and skin in the
skin manager.
Now we're going to choose an element in the list.
And then we're going to see which number this element has to make a final decision.
Um, let's go to play mode.
I'm going to show it to you so we can switch skins and we can see we switch in current skin index.
And as I mentioned before, we took this number and used it directly over here.
And also we passed this number directly to the skin manager.
What we're doing now is something different.
We take this number to choose element in the list over here.
And we chose number three.
And we can see that element three has skin index three.
But let's say first layer chose um.
Musk dude.
And we want to remove musk dude from the selection now because this one was chosen by the first player.
So we're gonna select the skin we're going to pass in photo skin manager.
And after that we're going to remove this element from the list like that.
Now zero element will have zero element one will have one and element two will have three.
And now when you switch between them you can only switch between these three.
And again this is why it's important to have a list because now current skin index will send us to element
two in the list.
And element two will have skin index of number three.
And.
Basically.
That's it.
That's what we're doing.
Then we're taking this number and we're giving it to Skin Manager.
And we also given this number to the animator layer.
Okay.
Very nice.
Now let's go ahead and make functionality further.
Uh, first of all, I would like to reset skin selection when we press back button.
Uh, we need to go.
Uh, maybe somewhere here we're going to make private void.
Reset skin choices.
Actually, this should be public because we're going to attach this method to the back button.
Or we could just call it on enable.
Yeah that's what we're going to do.
Let's keep it private.
So over here we want to take a list of skin index skin index list.
And we're going to make it equals to new list of integers.
In this way we're going to refresh the list every time we enable UI.
After that we're going to make for loop.
And as a length we're going to use skin list.
Skin list dot length.
So it means we're going to set up skin index list according to the amount of skins we have in the skin
list array.
And over here we're going to do skin index.
AD and we just want to add an index.
So we're going to add I over there.
This one will reset the list and it will fill it up with numbers.
Every time you enable UI we just need to go to UN enable.
Over here.
And we're going to do reset skin choices also, just in case we can do this in the week before we load
skin unlocks, not to break the system, reset skin choices.
Nice.
This is good.
Now we need to make a functionality that would help us to choose skins for the player for the first
one, and for the second one we have this select skin method.
And if we did not unlock the skin, we're going to buy it.
But if we did unlock the skill we're going to select it just to make code cleaner.
I'm going to take these two lines of code and I'm going to rub them into a method.
Select.
Um.
Now we already have select skin.
Let's do it like that.
Let's rename this to Select Skin button.
And this one going to be Select skin.
All right.
Very nice.
Uh, now we're going to have to reassign this button, but it's fine.
It's not that difficult to do over here.
We need to check something.
We need to check if this is the first player pressing the button or the second one.
Basically, we want to check for which player currently we selecting the skin.
If current player index is lower than maximum player count, then we still selecting the skin.
We can just confirm it and save the info.
But if we choosing the last skin for the last player, then we're going to switch UI.
To do all of that.
We need to keep track of player index that we currently have while we are in the UI.
So this is how we're going to do that.
We're going to go here and we're going to make public values.
I just want you to see them.
But later we're going to hide the values.
You're going to do public.
Int max player count and then public int current player index.
Maybe let's be consistent and let's rename this to index.
So max player index and current player index these two values that we're going to use.
And let's go to reset skin choices and update these values just in case.
So over here in the reset skin choices I'm going to do um, max player index is equals to player manager
instance max player count.
And then I'm going to do current skin index equals to zero.
And I guess this one should be minus one, right?
Because we do max player count on the player manager from one, not from zero.
Okay, let's see how it's going to work.
Should be fine.
So now we have current.
Sorry, this should be current player index.
Current player index.
So now we have uh information about current player index and maximum player index we can go to skin
selection.
Method.
Inside of this method.
First we want to get the selected skin index.
I'm going to do it in a very simple way.
In selected skin index equals to skin index with the current skin index.
So now we have number from the list that we need to use to choose the skin.
Then we're going to do.
If current player index is less than max player index it means we still choosing skin not for the last
player, but for the previous one for the first player.
And if that's the case, we can just choose the skin.
You're going to drag this line of code over here, you're going to pass.
Selected skin ID, and as a player, we're going to just pass.
Uh, current player index like that.
And then we want to increase current layer index.
And in this way, next time we press in this button we're going to choose skin for the next player.
Then over here we're going to do else.
And inside of this else statement we're just going to select the skin for last player that we have.
Like that, and then we just want to switch UI to the next one like that.
All right.
This is all what we need.
Let me just explain once more, just in case.
So we have current layer index.
And if this value is less than max player index it means we just need to choose the skin.
And then we need to prepare skin selection for the next player.
So we're choosing the skin.
And we're saying that current layer index is plus plus.
So go and pay attention to the next player.
Then once this statement is not met means current layer index is equals or bigger than max player index,
then it means we're working with the last layer we have.
And in that case we just need to set skin ID on a skin manager and switch UI to level selection.
Simple as that.
Okay.
Uh, now let's go ahead and let's set up methods and let's see if it all works.
Because I could forget something.
Uh, let's go to the scene.
Let's open skin selection.
This one is okay.
We just need to take this select button, and we need to, uh, change method over here.
To select skin button.
And I think this should be good.
We probably have to add another text so we know for which player we currently choose in a skin.
I'm going to take the skin price.
Duplicate it.
Move it above.
Let's do a player number.
Next.
Also, you could put text here.
Okay.
And inside we need just a player number.
Text.
Uh, we don't need I can I'm going to delete it.
And the text itself.
I'm going to do alignment in the center like that.
That's just increase text box over here.
And this should be good.
Let's say this one says.
First layer.
Nice.
Now let's go and update this text as well on the button just in case.
Uh, we're going to need the reference to this text.
All the way above, we're going to need this serialized field private Text, mesh Pro GUI, layer number
text.
And then we need to go to the.
Update skin display.
And over here I'm going to take the button up layer button number text dot text equals to.
You're going to give it a player's number.
And we start indexation from zero.
And if that's the case then I'm going to do current player index plus one.
So we don't start from zero we start from one.
And then I'm going to do plus player.
Just like that should be good.
Let's go back.
We need to find this text.
We need to give text over here.
And I'm going to start everything from main menu because I want to do two players selection.
To player over here.
Normal.
Now we have skin selection UI first player is choosing the skin.
You can switch.
Sorry.
You can switch left and right.
Just like that.
We can see we changing current skin index and max player index is one.
Current player index is zero, so it should be fine.
If you are a bit confused by these numbers, you can just start indexation from one and do max player
index equals to max player count on a player manager.
So let's say my first player chooses the ninja frog.
I'm going to press enter.
Now we can see we have message second player.
And I can see this skin did not disappear.
And also we did not remove index from the list.
So that is my mistake.
Uh, let's go and fix it now before we check anything else.
We just need to go to Select skin.
And over here, every time we select a skin we want to do um.
Skin index dot.
Remove current skin index.
Yes, just like that.
And maybe.
Should we remove it here?
I think it's not important because this is the last selection, so it doesn't really matter.
Uh, let's go and try again.
Let's go to unity.
Play to players normal.
So first player choosing the skin.
Let's say first player choosing ninja frog going to press enter.
We did update skin display.
We did remove it from skin index list over here.
So now we have zero two and three.
Second player can switch between these three only.
This is good.
Uh index is updated over here.
This is good.
Text on the button is updated.
This is good.
Now let's take a look at the skin manager.
Okay.
Element zero chose skin index one, which is correct.
Now let me choose Pinkman for the second layer.
I'm going to press enter.
We can see skin manager has index three under element one, so it's fine.
Doesn't really matter what happened with the skin selection now, because it should be okay anyway.
But before we go to level and test this, I'm going to click back button and I'm going to try to check
things again because I want to be sure we resetting the skins if player like did the wrong choice and
they want to choose again.
Okay.
And you can see it was not updated for the second player, right?
I'm going to click back play to players normal and we have text second player, although other variables
are fine.
So what we need to do here is something very simple.
We doing this?
Reset skin choices on enable in which we reset the current layer index, but we do not update skin display.
And that may be the issue.
And let's do update skin display here.
Just in case.
I'm going to save everything and we're going to try again.
Let's go to play mode.
Play to players.
Normal.
Uh, first player chooses Ninja Frog.
Second player chooses the mask.
Dude.
Now they like.
Oh, wait, I want to do another one.
They're going back.
Play two players.
Normal.
It is.
Reset it.
And it's fine, although it is reset to the ninja frog I guess because we did not reset current skin
index.
So if you want to reset to zero, you can do that.
But I think I'm going to just maybe keep it as it is.
It's okay.
It doesn't really matter.
Yeah.
So let's say first layer chooses the Pinkman.
Second one chooses the ninja frog.
We have this info on a screen manager.
We're choosing the level.
We're going to level itself.
I'm going to press the enter and first player is a Pinkman.
Yay.
Now let me take the second one.
Join.
It's a ninja frog, just as we chose.
Now let's say the first player dies and he responds and the second player dies and he cannot respond.
It's okay.
All right.
So system works.
Let's go to next level.
We are on the next level and we are there.
I had an extra player there, but it's okay, we just need to change it on the scene itself.
It's fine.
Hey, boy.
Come here.
Let's finish the game.
Okay?
I can see a couple of places for cleanup, but we're going to do that, um, in the next video.
The skin selection.
UI itself works great.
Again, if you want to reset skin selection fully, you can go to Reset Skin Choices and you can do
current skin index equals to zero.
Then it will choose the first one that it has in the list.
Okay, I think that's it.
Thank you so much for paying attention.
Let's go to the next video and I'll see you there.