WEBVTT

00:00.020 --> 00:00.440
Hello guys.

00:00.440 --> 00:01.370
Welcome to the video.

00:01.370 --> 00:06.110
In this one I want to show you how to set up difficulty for more than one player.

00:06.110 --> 00:08.540
Because as of now, system works only for one player.

00:08.540 --> 00:12.800
And if we have two players in the game and one of them will die, then it will restart the level.

00:12.800 --> 00:13.670
That's not what we need.

00:13.670 --> 00:19.490
So I want to introduce a live count in this video so players can have a live points that they can spend

00:19.490 --> 00:20.510
to respawn.

00:20.510 --> 00:24.170
But before we do that, let's fix that bug that we've seen in the last video.

00:24.170 --> 00:26.450
So I did spend some amount of time to check what's up.

00:26.450 --> 00:27.950
And I found the problem.

00:27.950 --> 00:31.820
I found the root of the problem and let me explain it to you first.

00:31.820 --> 00:34.130
So when we die it is fine.

00:34.130 --> 00:38.960
And then when we're using the second player and pressing the jump button, we can see these two bugs

00:38.960 --> 00:39.770
over here.

00:39.770 --> 00:47.570
And first message over here gives us an information meeting reference exception while executing performed

00:47.570 --> 00:49.460
callbacks of a player jump.

00:49.460 --> 00:55.040
Also, if you go here, it leads you to this method of a private void jump.

00:56.040 --> 00:59.280
Because that was used first when I pressed the jump button.

00:59.340 --> 01:04.200
And the problem is actually not in the dust fix or anything else in here.

01:04.230 --> 01:10.200
The problem is that we're trying to use jump method from a player that we destroyed.

01:10.500 --> 01:15.150
It means that we did not unsubscribe from the event when player died.

01:15.150 --> 01:16.290
That's the problem.

01:16.320 --> 01:20.040
Now look, I died only once and I have this message once.

01:20.040 --> 01:25.200
If I die again and try to jump again, you'll see this message twice.

01:25.200 --> 01:30.870
Because now we're trying to access two players that were destroyed before I got this.

01:30.870 --> 01:33.180
Because we can see a message over here.

01:33.480 --> 01:35.220
I'm missing reference exception.

01:35.220 --> 01:41.010
The object of type has been destroyed, but you are still trying to access it, so that's the problem.

01:41.010 --> 01:43.350
We do not unsubscribe from the event.

01:44.390 --> 01:51.200
Uh, luckily for us, I found the fix, and it works like that because of the change we did to the.

01:52.030 --> 01:56.830
Input system over here, so we will have to adjust it slightly.

01:56.830 --> 02:00.310
And before we do all of that, let me take these two methods.

02:00.310 --> 02:05.050
And I want to move them all the way down here because they take a lot of space and they're just in the

02:05.050 --> 02:08.080
beginning of the script, and we do not come back to them so often.

02:08.080 --> 02:08.410
Right?

02:08.410 --> 02:11.110
Besides, we're going to have to create three new methods here.

02:11.110 --> 02:12.760
So I'm going to keep all of the input below.

02:12.760 --> 02:14.380
Now what is happening here.

02:14.380 --> 02:17.050
We do not unsubscribe from the event on disable.

02:17.050 --> 02:18.220
That is the problem.

02:18.220 --> 02:20.620
Luckily for us it's a very easy fix.

02:21.220 --> 02:23.230
Um, let's start here.

02:24.430 --> 02:32.200
We're going to remove this and we're going to type on jump performed just like we did in the player

02:32.200 --> 02:36.370
manager over here with the add player in a very similar way.

02:36.400 --> 02:39.940
Then we're going to click Alt Enter to Generate method.

02:40.180 --> 02:42.850
And over here we have a method with a context.

02:42.850 --> 02:47.470
If you cannot generate method with a hotkey just like I did, you can manually write the same method

02:47.470 --> 02:48.580
and it will work.

02:48.760 --> 02:50.980
I want to move it below over here.

02:52.330 --> 02:54.820
And then inside we're going to call jump button.

02:54.820 --> 03:01.420
And also I forgot to use buffer jump in the previous input we had.

03:01.420 --> 03:05.080
So we need to do attempt buffer jump.

03:05.080 --> 03:07.060
That's what we need to do okay.

03:07.960 --> 03:09.100
Very nice.

03:09.100 --> 03:14.710
Now let's go here and let's do minus equals on jump performed.

03:18.520 --> 03:19.090
Cool.

03:19.090 --> 03:22.570
Now let's go ahead and check if this one fixes the issue.

03:22.870 --> 03:24.190
I'm going to go to play mode.

03:27.230 --> 03:33.680
Uh, I'm gonna make the character going to kill him, read a new one, and there is no more bugs like

03:33.680 --> 03:37.340
we had before, so it works correctly.

03:37.340 --> 03:38.120
I love it.

03:38.120 --> 03:42.380
Now let's go back and let's do this adjustment for these two lines of code over here.

03:42.380 --> 03:48.110
So I'm going to just remove it and I'm going to type on movement performed.

03:48.110 --> 03:50.690
Let's generate method inside.

03:50.690 --> 03:57.410
We're going to do uh move input equals to context of read value vector two.

03:57.680 --> 04:02.660
And basically it's the same as we had before just in a method that's the same job.

04:03.170 --> 04:06.320
Uh on movement canceled.

04:06.920 --> 04:08.720
We're going to do generate method.

04:10.210 --> 04:12.940
Move input equals to vector 2.0.

04:13.540 --> 04:14.290
Nice.

04:14.320 --> 04:16.720
Now we need to go over here.

04:17.340 --> 04:19.710
And replace it in the same way.

04:20.280 --> 04:24.660
On movement cancelled and on movement performed.

04:26.860 --> 04:27.460
Right.

04:27.460 --> 04:29.260
This will fix the problem.

04:29.290 --> 04:30.220
Very nice.

04:30.220 --> 04:33.130
Now let's continue development of the player manager.

04:34.410 --> 04:37.350
I want to have a player's life count in the game.

04:37.350 --> 04:42.540
So we need to make a life count and we need to deduct points from that life count every time player

04:42.540 --> 04:43.200
dies.

04:43.740 --> 04:48.570
And then if we don't have lives anymore, we need to disable ability to join the game.

04:48.930 --> 04:50.550
So let's start with simple.

04:50.550 --> 04:52.650
Let's make UI so we can see lives.

04:52.650 --> 04:55.260
I'm going to take fruit UI, duplicate it.

04:55.680 --> 04:57.480
Let's rename it to.

04:59.170 --> 05:01.810
Life point UI.

05:03.570 --> 05:05.340
And I'm going to attach it to the center.

05:05.340 --> 05:09.270
And these elements have a -22 on the Y.

05:11.110 --> 05:12.940
So I'm going to do the same over here.

05:12.940 --> 05:14.080
-22.

05:17.150 --> 05:19.190
Okay, let's change the icon as well.

05:19.310 --> 05:20.750
This can be changed to.

05:21.750 --> 05:24.210
Lifepoints text and.

05:25.350 --> 05:32.580
Life Points icon and we can go to Project Graphics main character virtual GUI.

05:32.580 --> 05:36.930
Let's take the idle sprite and drag it on the icon over here.

05:37.610 --> 05:40.670
I think we can reduce size to 100 by 100.

05:41.960 --> 05:45.650
And let's just move it above a little bit like that.

05:47.210 --> 05:48.710
And maybe we can flip it.

05:50.210 --> 05:51.260
Okay, good.

05:51.260 --> 05:53.000
Now we have a UI.

05:53.390 --> 05:59.300
Let's go ahead and make a method on the UI in game script so we can update this UI.

06:01.120 --> 06:03.100
Going to make a reference serialize field.

06:03.100 --> 06:07.480
Revit text mesh Pro guy life.

06:08.080 --> 06:13.120
Lifepoints text and then somewhere below.

06:14.650 --> 06:16.360
We need a method.

06:17.770 --> 06:20.350
Public void update.

06:20.980 --> 06:23.950
Life points UI.

06:25.480 --> 06:29.320
Going to do live points text that text equals to.

06:29.320 --> 06:36.430
And we need to variables over here int live points and int max live points.

06:37.630 --> 06:44.980
Okay then let's go here and do live points plus slash plus max live points.

06:45.340 --> 06:46.810
Okay, I like it.

06:46.870 --> 06:50.710
Now, the only thing we need to do is to have the values for this method.

06:50.920 --> 06:52.990
We can do that on a player manager.

06:53.140 --> 06:54.190
So.

06:55.390 --> 07:01.270
I'm going to make a variable public int life points.

07:01.930 --> 07:02.530
Okay.

07:02.530 --> 07:08.770
And I think we can have max player count as a maximum life points, so each player can die only once,

07:08.770 --> 07:10.810
or one of the players can die twice.

07:10.810 --> 07:12.070
I think this is acceptable.

07:12.070 --> 07:13.120
I like the idea.

07:13.120 --> 07:14.710
So we're going to go.

07:15.510 --> 07:20.790
To the place where we remove the player and we're going to do live point minus, minus.

07:20.790 --> 07:26.880
And then if live points is less or equals to zero, it will mean we do not have live points anymore.

07:26.880 --> 07:34.110
And we can take player input manager disable join in and this will stop ability to join the game.

07:34.110 --> 07:42.750
Also, every time we remove the player, let's do UI in game instance, update live points UI and we're

07:42.750 --> 07:48.480
going to give it live points as a current value and max player count as a maximum value.

07:49.930 --> 07:50.800
Very nice.

07:50.800 --> 07:54.250
Let's save this and let's go back.

07:57.450 --> 08:02.310
And we need to assign this lifepoints text like that.

08:02.310 --> 08:08.190
Also, we need to go to player manager and let's say we have max player count two and Lifepoints two.

08:08.190 --> 08:09.720
Let's go to the game.

08:14.390 --> 08:16.370
Why did we not update the text?

08:16.790 --> 08:17.870
Because that's why.

08:17.870 --> 08:21.230
Because by default we need to update text by default as well.

08:21.230 --> 08:22.400
We're going to do that later.

08:22.400 --> 08:25.010
As of now let's do two out of two okay.

08:25.010 --> 08:27.410
So I'm joining the game I have two lives.

08:27.410 --> 08:28.070
We can see that.

08:28.070 --> 08:31.040
And there is a second player joining the game with a gamepad.

08:32.670 --> 08:33.390
Come on, boy.

08:33.630 --> 08:35.760
Oh, I have Bluetooth switched off.

08:36.150 --> 08:37.530
Okay, now should be good.

08:40.980 --> 08:41.460
Yeah.

08:41.460 --> 08:42.180
Connected.

08:42.210 --> 08:43.680
There is a second layer.

08:43.710 --> 08:47.100
Now I'm going there and I'm going to kill it.

08:47.100 --> 08:49.260
And we have one out of two lives.

08:49.290 --> 08:52.170
Then second layer go in there and.

08:52.880 --> 08:58.130
Get damage and there is zero out of two and we cannot respawn the player anymore.

08:58.610 --> 09:01.100
Uh, joining is disabled.

09:01.100 --> 09:01.970
Very good.

09:01.970 --> 09:07.160
So now when that happens, instead of just doing nothing, we can restart the game just like we did

09:07.160 --> 09:07.940
before.

09:08.000 --> 09:09.710
Let's go to player manager.

09:11.700 --> 09:14.400
And over here we're going to check.

09:16.160 --> 09:23.510
If we have no life points anymore, we're going to do a game manager instance restart level just like

09:23.510 --> 09:24.050
that.

09:24.080 --> 09:25.250
Very nice.

09:25.310 --> 09:27.830
Now there is another thing we need to do.

09:27.830 --> 09:34.640
This one will disable drowning on level restart and it will not be enabled when you start the game again,

09:34.640 --> 09:41.810
because in the future we're going to need to set this GameObject to don't destroy on load.

09:41.810 --> 09:42.770
It's going to be like this.

09:42.770 --> 09:48.500
Don't destroy on load this GameObject, because we're going to need to set default values on this GameObject

09:48.500 --> 09:49.610
in the main menu.

09:49.610 --> 09:55.040
So let's keep it like that and let's see what is going to happen when you restart the level after death.

09:55.640 --> 09:56.720
Let's go there.

10:03.810 --> 10:05.190
Gonna kill it again.

10:05.730 --> 10:07.320
And we restarting the level.

10:07.320 --> 10:14.520
And now I cannot join the game because this object is not destroyed on load, and this object of the

10:14.520 --> 10:18.570
player manager have joining enabled as false.

10:18.570 --> 10:20.340
And we cannot add new player.

10:20.340 --> 10:21.900
So we need to fix it somehow.

10:21.900 --> 10:28.650
And I think we should make a method that would enable joining and update live count in the player manager.

10:28.650 --> 10:33.570
But every time it's going to be called from the game manager in the start method, because we have game

10:33.570 --> 10:39.810
manager on each new scene and their start will be called every time we load new scene.

10:39.810 --> 10:40.680
So.

10:42.010 --> 10:43.870
Let's go and make a method.

10:45.280 --> 10:47.410
Um, public void.

10:49.000 --> 10:50.890
Enable join.

10:52.280 --> 10:55.220
And update life points.

10:55.250 --> 10:57.020
It's pretty long one, but it's okay.

10:57.050 --> 10:59.300
Then we're going to do player input manager.

10:59.840 --> 11:01.820
Enable join in.

11:02.210 --> 11:07.550
And we're going to do uh live points equals to max player count.

11:07.940 --> 11:14.870
And also we want to uh take UI in game instance update live points UI.

11:15.350 --> 11:20.150
And we're just going to do live points max player count just like that.

11:20.420 --> 11:22.970
And then we need to go to the game manager.

11:25.100 --> 11:31.220
And in the start method, after we make sure we did create all of the managers, we're going to do player

11:31.220 --> 11:32.180
manager.

11:32.830 --> 11:37.750
Dot instance, enable join and update live points.

11:39.320 --> 11:39.950
Very good.

11:39.950 --> 11:45.380
This not only will help us with the level restart, but also it will help us not to create a player

11:45.380 --> 11:51.110
in the main menu because there we'll disable this by default and it will be enabled from the game manager

11:51.110 --> 11:52.940
every time we start the level.

11:53.670 --> 11:55.530
So let's go ahead and try this.

11:56.520 --> 11:56.970
Okay.

11:56.970 --> 11:59.670
We've got two out of two going to make a player.

11:59.700 --> 12:00.510
Kill it.

12:00.510 --> 12:04.380
Then second player joins, goes there, we kill it.

12:04.380 --> 12:07.470
Level is restarted and we have everything again from the start.

12:07.470 --> 12:09.510
And it works clean and nice.

12:09.510 --> 12:12.660
Okay, I see a message there, so I need to double check.

12:12.660 --> 12:13.770
What does it say?

12:15.790 --> 12:18.730
Multiple player input managers in the game.

12:19.900 --> 12:20.470
Okay.

12:20.470 --> 12:23.920
It is fine because it is getting destroyed.

12:24.870 --> 12:25.920
From the awake.

12:25.950 --> 12:29.160
Yeah, we can ignore it because the extra object is destroyed.

12:29.160 --> 12:29.970
It's fine.

12:30.330 --> 12:33.120
Let's do this game object.

12:34.290 --> 12:34.830
Nice.

12:34.830 --> 12:38.550
Now another problem we need to fix is the player's reference.

12:38.550 --> 12:43.260
We have this variable over here that is accessed by many scripts in the game.

12:43.260 --> 12:46.830
And we need to solve this somehow, because now we can have more than one player.

12:46.830 --> 12:49.170
So I'm going to remove it from here.

12:49.170 --> 12:54.840
It will show me a bunch of errors, and we can see to which places we need to pay attention.

12:55.910 --> 12:59.540
Let's click over here and let's find one of the.

13:00.290 --> 13:02.870
Lines are over here.

13:02.870 --> 13:03.380
Okay?

13:03.380 --> 13:05.030
This one is not needed anymore.

13:05.030 --> 13:06.380
We can safely remove it.

13:06.380 --> 13:08.090
This was just a placeholder.

13:09.770 --> 13:11.420
Now let's see what else.

13:12.800 --> 13:13.160
Um.

13:13.160 --> 13:19.430
Over here, when we pause the button, we get an access to the player, and that is done only to disable

13:19.430 --> 13:20.060
the input.

13:20.060 --> 13:21.200
We need to do the same.

13:21.200 --> 13:28.340
But for all of the players in the game, I think we have to go to the player manager first, and we

13:28.340 --> 13:31.910
need to make a method that would return us this list.

13:32.030 --> 13:34.190
So let's go somewhere below.

13:35.020 --> 13:42.490
And let's make a public list of player, and we're going to give it a name of get player list.

13:43.760 --> 13:46.010
It's going to return me player list.

13:46.100 --> 13:47.270
Just like that.

13:47.300 --> 13:48.860
Now let's save this.

13:49.810 --> 13:51.910
Let's go to UI in game.

13:52.180 --> 13:53.290
All the way above.

13:53.290 --> 13:54.370
Over here.

13:54.490 --> 13:56.620
We can make it as a list.

13:57.630 --> 13:59.070
List of player.

13:59.720 --> 14:01.490
And let's name it as player list.

14:02.060 --> 14:06.470
Uh, let's click alt enter, use system collection generics.

14:06.830 --> 14:10.280
And then we're going to go back to that pause button method.

14:13.150 --> 14:14.110
Over here.

14:14.440 --> 14:22.660
And instead of this we're going to do player list equals to player manager dot instance get player list.

14:23.050 --> 14:23.710
Okay.

14:23.740 --> 14:27.100
Now we need to disable input for each player in the list.

14:28.540 --> 14:30.760
We can do something like.

14:31.580 --> 14:32.150
This.

14:33.600 --> 14:34.440
For each.

14:35.960 --> 14:37.370
VAR in player list.

14:37.370 --> 14:38.300
Player.

14:38.660 --> 14:39.740
Player input.

14:39.740 --> 14:40.730
Disable.

14:41.240 --> 14:42.890
Then I'm going to copy this.

14:44.450 --> 14:48.320
Paste this in here and we're going to do enable.

14:50.800 --> 14:53.230
All right, now let's go and double check this.

14:53.770 --> 14:55.240
I'm going to go back.

14:58.270 --> 15:02.350
There is some other message we have on the enemy and this will be fixed.

15:02.350 --> 15:03.100
No worries.

15:03.100 --> 15:04.450
For now, let's just, uh.

15:05.630 --> 15:06.560
I'm in the salt.

15:08.610 --> 15:11.850
Okay, let's go back and do this.

15:12.640 --> 15:14.170
We're going to go to play mode.

15:17.500 --> 15:19.360
I'm going to make two players.

15:19.660 --> 15:23.770
I'm going to pause the game and none of them can be controlled.

15:23.770 --> 15:24.490
This is good.

15:24.490 --> 15:26.320
Now I'm going to unpause the game.

15:26.320 --> 15:30.880
We are back in the game and we can control characters very well.

15:30.880 --> 15:32.770
Now for the enemies.

15:32.770 --> 15:37.990
This one is on the enemy and in this one we updated the reference of the player.

15:37.990 --> 15:39.790
So that's what we need to do.

15:40.910 --> 15:44.450
But now I guess it's better to use list as well.

15:44.900 --> 15:48.890
Uh, just in case we want to have access to all of the players.

15:48.890 --> 15:50.660
So let's go ahead.

15:51.940 --> 15:53.380
Whereas the players reference.

15:53.380 --> 15:54.130
Can I see it?

15:54.130 --> 15:55.780
Oh, it's a transform.

15:56.460 --> 15:57.600
All right.

16:00.200 --> 16:00.890
Okay.

16:01.130 --> 16:02.420
This what are we going to do?

16:02.780 --> 16:06.740
We're going to turn it into a layer and it's going to be a list.

16:08.320 --> 16:09.340
Of players.

16:10.110 --> 16:13.410
Um player list, same as we did just now.

16:13.740 --> 16:17.310
And then when we need transform, we're going to get access to the transform.

16:17.310 --> 16:17.910
Okay.

16:17.910 --> 16:18.900
So player list.

16:18.900 --> 16:19.740
Very good.

16:19.740 --> 16:22.830
Now let's go down here and instead of.

16:24.890 --> 16:27.020
This we're going to do player list.

16:27.110 --> 16:30.950
Equals to player manager dot instance get player list.

16:30.950 --> 16:32.030
Just like that.

16:32.090 --> 16:35.540
And now we want to call this method when player responds.

16:35.540 --> 16:37.520
And also when player dies.

16:37.520 --> 16:38.660
This is what we want to do.

16:38.660 --> 16:39.920
So.

16:41.050 --> 16:42.520
Let's go to player manager.

16:43.490 --> 16:45.680
And I guess we can make another action.

16:45.680 --> 16:52.640
Just to make it clear and understandable, I'm going to do public static event on player death.

16:53.480 --> 16:54.050
Okay.

16:55.350 --> 16:57.360
Let's go to remove player.

17:01.870 --> 17:03.850
We're going to invoke it here.

17:04.360 --> 17:05.560
We're going to do it above.

17:05.560 --> 17:06.310
No, no, wait.

17:08.870 --> 17:11.180
We can just invoke it in the end.

17:12.020 --> 17:14.150
On player death not equals to null.

17:14.150 --> 17:16.790
Then invoke like that.

17:18.040 --> 17:20.530
And then on the enemy.

17:21.750 --> 17:27.120
We need to go here and do player manager on player death.

17:28.820 --> 17:30.500
Update layers reference.

17:31.160 --> 17:33.770
And then we need to unsubscribe from this.

17:34.310 --> 17:35.720
So we're going to go.

17:36.770 --> 17:37.100
To die.

17:37.100 --> 17:37.820
Method.

17:37.820 --> 17:38.840
Player manager.

17:39.320 --> 17:40.370
On player death.

17:40.370 --> 17:41.390
Unsubscribe.

17:42.100 --> 17:43.000
Very nice.

17:43.000 --> 17:43.720
Love it.

17:43.720 --> 17:46.600
So this does half of the job.

17:46.600 --> 17:48.910
Now we still have to do something here.

17:49.180 --> 17:56.290
Enemy chicken uses players reference over here to flip to know where it needs to run.

17:56.290 --> 17:58.210
We can see a message here with an error.

17:58.210 --> 18:01.420
So what I want to do is something pretty simple.

18:02.440 --> 18:07.840
I want to update the reference of a player according to the amount of players we have, and we're going

18:07.840 --> 18:12.190
to check how many players is there, and we're going to choose the closest one because chicken is supposed

18:12.190 --> 18:15.490
to chase the player, so it's fine if she has a closest one.

18:15.490 --> 18:17.260
I think that's a pretty good solution.

18:17.260 --> 18:19.540
So let's go and make.

18:20.710 --> 18:23.230
I want to transform player.

18:24.160 --> 18:25.330
Very nice.

18:25.420 --> 18:27.040
Now we're going to go.

18:28.560 --> 18:29.130
Here.

18:29.130 --> 18:33.180
First of all, we don't need to use transform because player is a transform.

18:33.180 --> 18:34.080
It's fine.

18:34.710 --> 18:38.820
And then somehow we need to update this information and it should be relevant.

18:38.820 --> 18:41.580
And also it should be updated like pretty often.

18:41.580 --> 18:45.300
So I think it would be a good idea to do it in the flip.

18:45.300 --> 18:49.440
Every time chicken flips is going to check where is the closest layer.

18:49.590 --> 18:54.840
And so this would be going to do we want to have float closest distance.

18:55.690 --> 18:57.580
Equals to float max value.

18:57.580 --> 18:59.980
So this will have the biggest value there can be.

18:59.980 --> 19:02.410
And then we're going to check distance to each object.

19:02.410 --> 19:08.470
And if new distance is less than current closest distance then we're going to update closest distance

19:08.470 --> 19:09.910
to the new value we've got.

19:09.910 --> 19:15.730
Um let's do this for each for each player P in player list.

19:15.730 --> 19:17.980
So we're going to check each player in the list.

19:17.980 --> 19:28.420
We're going to do float distance to player equals to vector two dot distance from transform.position.

19:29.290 --> 19:32.680
To t transform position.

19:33.510 --> 19:41.730
Then if distance to player is less than closest distance means we found our new closest distance and

19:41.730 --> 19:46.020
we need to update it, we're going to do closest distance equals to distance to player.

19:46.020 --> 19:52.290
And also we want to update player reference because now we found new closest player.

19:52.290 --> 19:56.940
So I'm going to do player equals to p transform.

19:58.020 --> 19:58.500
Very good.

19:58.500 --> 20:00.300
So this is supposed to do the job?

20:00.570 --> 20:02.550
Uh, maybe let's wrap this into a method.

20:04.280 --> 20:05.330
Extract method.

20:06.020 --> 20:09.380
Find closest layer.

20:09.800 --> 20:10.730
Just like that.

20:12.590 --> 20:13.700
And it should be good.

20:14.900 --> 20:19.130
Uh, there might be something else, but to be very honest.

20:19.130 --> 20:19.340
Oh.

20:19.340 --> 20:20.180
What is it?

20:22.930 --> 20:23.410
What did.

20:23.410 --> 20:24.820
What does it say?

20:25.820 --> 20:30.110
The event is never used over here on player manager.

20:30.110 --> 20:34.220
We need to go and check if we invoking the on player death.

20:34.430 --> 20:38.600
And I did make a mistake because this one should say on player death.

20:41.620 --> 20:42.460
Very nice.

20:42.670 --> 20:44.410
Uh, one more adjustment I want to do.

20:44.410 --> 20:47.800
As of now, when we have two characters in the game, they can push each other.

20:47.800 --> 20:49.870
And I don't mind if player cannot pass by each other.

20:49.870 --> 20:50.470
I like it.

20:50.470 --> 20:54.100
And also, I like when you can stand on the head of the another player.

20:54.100 --> 20:59.110
So we're going to go ahead to the asset prefab.

20:59.800 --> 21:00.850
Player.

21:00.850 --> 21:09.910
Let's make a 2D sprite square and we need to add a box collider 2D on this, and I want to place it

21:10.510 --> 21:12.130
on the head of the character.

21:12.130 --> 21:13.630
Something like that.

21:13.630 --> 21:15.190
Yeah, this should work.

21:16.710 --> 21:18.780
Now let's make it a bit slimmer.

21:21.980 --> 21:23.420
And let's give it a name.

21:23.420 --> 21:25.280
Something like a head.

21:26.800 --> 21:27.640
Later.

21:27.640 --> 21:33.400
Now we want to go to layers and we're going to add layer players.

21:34.060 --> 21:34.660
Had.

21:35.570 --> 21:36.050
Okay.

21:36.050 --> 21:40.400
Now let's take this object and let's enable players head over here.

21:40.700 --> 21:44.960
Then we want to go to Edit Project Settings Physics 2D.

21:45.740 --> 21:47.060
And.

21:47.750 --> 21:51.200
None should be able to collide with this except the player.

21:51.200 --> 21:54.710
So I'm going to disable everything except the player.

21:54.710 --> 21:55.730
Just like that.

21:57.260 --> 21:58.610
Then let's close it.

21:58.610 --> 22:00.770
Let's select the player itself.

22:00.770 --> 22:04.760
And on what is ground we're going to choose player's head as well.

22:04.760 --> 22:09.830
So now we are supposed to be able to stand on the head of another player.

22:09.830 --> 22:12.890
Let's make it slimmer like that.

22:13.160 --> 22:14.930
And let me double check this.

22:16.330 --> 22:18.010
It should be good and it should be fun.

22:20.120 --> 22:21.950
So I'm going to join and stand here.

22:21.950 --> 22:26.540
And then second player is there, and he can stand on the head of the character and jump from it.

22:26.540 --> 22:33.260
And now you can make lots of nice puzzles where one player should give another player, uh, a platform

22:33.380 --> 22:35.060
so you can jump from it.

22:35.060 --> 22:36.140
Yeah.

22:36.140 --> 22:36.590
Nice.

22:36.590 --> 22:37.010
Right?

22:37.010 --> 22:39.590
What if I run and it doesn't move together?

22:39.590 --> 22:40.670
Would be fun also.

22:40.670 --> 22:42.380
But if you move together.

22:44.370 --> 22:46.920
Yeah, this could be fun, man, I like it.

22:48.220 --> 22:48.910
Good.

22:50.650 --> 22:52.240
Um, there is something else.

22:52.240 --> 22:55.300
As of now, we do not use difficulty of the game.

22:55.300 --> 22:57.400
It's not working in any way.

22:57.400 --> 22:59.590
So this is what we need to do.

23:00.690 --> 23:05.940
First of all, on player manager, we removing the life.

23:05.940 --> 23:13.020
In any case, even if it's an easy mode and on player we did remove fruits only if this is a normal

23:13.020 --> 23:14.310
difficulty, right?

23:14.310 --> 23:16.290
So this is what I want to do here.

23:16.290 --> 23:21.270
I think we can, uh, let's remove this as well.

23:21.270 --> 23:23.700
And, uh, give me a second.

23:23.700 --> 23:24.990
I need to think.

23:24.990 --> 23:27.180
I think we can keep this one as it is.

23:27.180 --> 23:30.960
We just need to go to player manager and use game difficulty here.

23:30.960 --> 23:32.040
So.

23:32.650 --> 23:40.330
We can do lifepoints only if difficulty is normal and we don't have any fruits, or if difficulty is

23:40.330 --> 23:41.260
difficult.

23:41.740 --> 23:42.790
Uh, I mean hard.

23:42.790 --> 23:46.900
So let's do private bull can remove.

23:47.780 --> 23:49.040
Life points.

23:49.460 --> 23:57.170
And over here we need to do something like if game manager dot instance dot fruits collected is less

23:57.170 --> 24:07.610
or equals to zero and difficulty manager dot instance dot difficulty equals to normal, then we can

24:07.610 --> 24:08.690
return true.

24:08.690 --> 24:17.150
Also we want to return true if difficulty manager instance difficulty says that difficulty is hard,

24:17.180 --> 24:20.270
then we also need to return true.

24:20.540 --> 24:23.840
And if no we're going to return false.

24:23.840 --> 24:26.090
Okay so how this works.

24:26.090 --> 24:29.690
We're using this boolean method to check if we can remove life points.

24:29.690 --> 24:32.150
And we check if it's a hard mode of the game.

24:32.150 --> 24:37.550
Then we return true and we're going to remove life point and none of this check will matter anymore.

24:37.820 --> 24:42.170
Then if this one is not true, if game is not hard, it's going to proceed further.

24:42.170 --> 24:48.860
And then it checks if fruits collected are less or equals to zero means we don't have any more fruits.

24:48.860 --> 24:52.430
And difficulty over here is normal.

24:52.430 --> 24:55.880
It means we can remove life points and we're going to return true.

24:55.880 --> 25:00.980
And if this condition is not met, then it's going to be skipped and we're going to just return false,

25:00.980 --> 25:03.230
which means we cannot remove life point.

25:04.130 --> 25:04.880
Okay.

25:06.560 --> 25:09.650
Let's do if we can remove live points.

25:12.110 --> 25:13.730
Then do minus five points.

25:13.760 --> 25:14.240
All right.

25:14.240 --> 25:15.200
This is supposed to work.

25:15.200 --> 25:16.430
Maybe there is a cleaner way.

25:16.430 --> 25:18.140
I'll think of it in the end of this section.

25:18.140 --> 25:19.640
As of now, this should be good.

25:19.640 --> 25:22.910
Now let's go to unity and let's try this.

25:22.910 --> 25:26.330
Now we don't need to update difficulty on the players prefab.

25:26.330 --> 25:29.090
We can only control that from a difficulty manager.

25:30.790 --> 25:33.880
And let's see, I'm going to change difficulty to normal.

25:33.880 --> 25:35.770
I'm going to collect some fruits.

25:35.770 --> 25:40.900
And now I'm supposed to get damage and lose the fruit, but not the life point.

25:41.380 --> 25:42.820
And yes, that's the case.

25:42.820 --> 25:43.690
It's working.

25:43.690 --> 25:46.390
This will work for the second player as well.

25:48.240 --> 25:48.990
Yes.

25:48.990 --> 25:49.440
Okay.

25:49.440 --> 25:50.220
This is good.

25:50.220 --> 25:52.170
And now if I die, I'm losing life.

25:52.170 --> 25:52.800
Point.

25:53.440 --> 25:54.670
Nice.

25:54.700 --> 25:58.480
Now let's try this again with the hard difficulty.

25:58.660 --> 25:59.440
Can I go there?

25:59.440 --> 26:01.240
And it doesn't matter how many fruits I have.

26:01.240 --> 26:04.900
Because I'm losing life points, so it works.

26:04.930 --> 26:05.740
Love it.

26:06.960 --> 26:09.420
There is something else I want to do before we go further.

26:09.420 --> 26:11.580
And I promise this is the last one.

26:11.910 --> 26:19.230
If game is easy, then we don't need to see the lives at the top over here because you know there is

26:19.230 --> 26:23.040
no point of counting lives because you cannot lose the game.

26:23.040 --> 26:26.340
So if that's the case, then we need to disable this game object.

26:27.240 --> 26:29.970
I can go over here.

26:35.880 --> 26:38.370
And not to mess with the code too much.

26:38.400 --> 26:43.380
I'll just make this disabled if game is easy.

26:43.470 --> 26:51.720
So what I'm going to do if, uh, difficulty manager instance difficulty equals to easy.

26:54.230 --> 26:57.020
Then I'll take live points.

26:57.470 --> 26:58.400
Text.

26:59.100 --> 27:01.230
And transform parent.

27:01.980 --> 27:05.970
GameObject, set active faults and return.

27:06.360 --> 27:08.100
I think this is supposed to work.

27:08.100 --> 27:09.600
Let's go and try this.

27:12.700 --> 27:14.800
I'm going to go to asset prefabs.

27:14.800 --> 27:16.870
I'll take difficulty manager.

27:16.870 --> 27:18.400
I'll make it easy.

27:18.400 --> 27:22.180
I'll drag it here and let's go to game mode.

27:24.070 --> 27:25.120
And it's not there.

27:25.120 --> 27:32.020
It's fine and we can play the game and enjoy the game without being worried about losing it.

27:32.600 --> 27:33.560
All right.

27:33.710 --> 27:35.090
This is perfect.

27:35.150 --> 27:37.670
I don't think we need to do anything else for now.

27:37.670 --> 27:41.630
This is pretty much a lot of functionality we did in one video.

27:41.630 --> 27:44.720
There are still some things we need to do, but we're going to do them later.

27:44.720 --> 27:46.250
As of now, this is good.

27:46.250 --> 27:47.360
Let's wrap this up.

27:47.360 --> 27:49.490
Let's make it as normal.

27:49.490 --> 27:51.680
Let's apply overrides.

27:51.680 --> 27:58.490
Let's take skin manager, player manager in game UI and we can apply overrides on all of them.

27:58.490 --> 28:01.250
So it will be applied to different levels as well.

28:01.250 --> 28:03.650
And let's go I'll see you in the next one.
