WEBVTT

00:00.080 --> 00:00.590
Hello guys.

00:00.590 --> 00:01.640
Welcome to the video.

00:01.640 --> 00:05.360
In this one I want to show you how to set up the split screen.

00:05.360 --> 00:07.250
It is purely optional.

00:07.250 --> 00:11.930
I don't want to have this functionality in my version of the game, but I want to show you how to do

00:11.930 --> 00:12.140
that.

00:12.140 --> 00:13.640
So if you want, you can use it.

00:13.640 --> 00:15.020
It's pretty much fine.

00:15.020 --> 00:19.430
It's fun to play with, and I think it is as good as the system that we made together.

00:19.430 --> 00:24.980
But just my personal preference for this kind of game is not to have a split screen, but joint camera

00:24.980 --> 00:25.970
for two players.

00:25.970 --> 00:30.110
Nevertheless, I want to show you how to make the system and I'll keep it in the project.

00:30.110 --> 00:33.020
You can use it if you want, but I'm not going to.

00:33.020 --> 00:33.560
Okay.

00:34.300 --> 00:35.950
So how do we make it?

00:36.190 --> 00:42.430
Uh, let's go to level one, and I'm going to use level one as example to explain how do we set up split

00:42.430 --> 00:48.760
screen camera before we set up split screen camera we need to remove functionality that we have on the

00:48.760 --> 00:49.750
level camera.

00:50.440 --> 00:58.000
Uh, sadly for me, the split screen does not require as many things as we did need for this setup,

00:58.000 --> 00:59.650
so we'll have to remove it.

01:01.190 --> 01:06.350
Let's take this level camera and let's make an impact completely on the prefab.

01:06.350 --> 01:09.050
We want to remove this component over here.

01:09.260 --> 01:12.170
We want to go to level limits and delete them.

01:12.170 --> 01:18.350
We want to take camera center point and assign it to Cinemachine camera over here in this field.

01:20.600 --> 01:22.130
Over here in this field.

01:26.800 --> 01:28.780
Let's do lens ten.

01:30.350 --> 01:36.770
And this is going to be the camera that, uh, player use until he joins the game.

01:36.770 --> 01:41.090
Like the first look of the level before you press any key to join.

01:41.510 --> 01:44.450
Then on cinemachine limits, we don't need this component.

01:44.450 --> 01:45.740
I'm going to remove it.

01:47.230 --> 01:50.920
And on Cinemachine camera looks good to me.

01:50.920 --> 01:53.380
This level camera view can be removed.

01:54.610 --> 01:55.030
And.

01:55.030 --> 01:55.480
Yeah.

01:57.100 --> 01:59.200
Okay, let me cover all of this box.

01:59.200 --> 02:00.790
Collider can be removed.

02:01.570 --> 02:02.740
And this should be good.

02:02.770 --> 02:04.420
Now what do we need to do?

02:04.450 --> 02:08.590
This player manager has a functionality enables split screen.

02:08.590 --> 02:09.850
Lets enable it.

02:10.820 --> 02:15.170
Also there is a set fixed number of cameras you can set to two.

02:15.170 --> 02:17.570
But I want to show you the reason why we need to enable it.

02:17.570 --> 02:20.210
So for now I'm going to disable it and you'll see later.

02:20.210 --> 02:21.530
And then we're going to use it okay.

02:22.400 --> 02:22.910
Um.

02:23.690 --> 02:25.310
Now how it's going to be.

02:25.310 --> 02:32.090
We need to make a setup where we can store main camera and cinemachine camera for each player, because

02:32.090 --> 02:33.410
this is how it's supposed to be.

02:33.410 --> 02:39.020
We're going to have two main cameras apart from this one, and these two main cameras will be attached

02:39.020 --> 02:42.710
to two new different cinemachine brains.

02:42.710 --> 02:48.740
Each camera will take half of the screen and it will follow the player because it will have cinemachine

02:48.740 --> 02:49.400
brain.

02:49.400 --> 02:50.960
Okay, this what we need to do.

02:50.960 --> 02:57.320
So first of all, we need to make two new city machines, two new main cameras, and then we need to

02:57.320 --> 02:58.940
save them in some variable.

02:58.940 --> 03:00.530
So let's go to script.

03:01.780 --> 03:02.590
Camera.

03:02.740 --> 03:04.930
I'm going to make a script.

03:05.690 --> 03:08.720
Level split screen setup.

03:11.900 --> 03:13.070
On the script.

03:13.070 --> 03:21.440
We're going to make a public camera array, main camera and then public cinemachine camera.

03:23.310 --> 03:27.000
Cinemachine camera and this should be an array I forgot.

03:27.450 --> 03:27.870
Okay.

03:27.870 --> 03:28.470
Like that.

03:28.470 --> 03:29.190
Very good.

03:29.190 --> 03:30.660
Now let's save this.

03:30.660 --> 03:31.680
Let's go back.

03:33.570 --> 03:36.780
And we need to attach this component over here.

03:36.780 --> 03:40.140
And now we need to fill up these variables with cameras.

03:40.170 --> 03:40.860
Okay.

03:41.010 --> 03:43.560
Let's take Cinemachine camera from here.

03:43.560 --> 03:45.780
Let's duplicate it twice.

03:45.780 --> 03:52.110
And let's give it a name with a underscore one and underscore two just like that.

03:52.110 --> 03:56.490
Also let's make sure they have container and they do okay.

03:56.490 --> 03:57.480
This is fine.

03:57.690 --> 03:59.700
Now let's go to level camera.

03:59.700 --> 04:02.490
Let's drag Cinemachine and Cinemachine two.

04:02.520 --> 04:03.540
Very nice.

04:03.540 --> 04:08.430
Now we need two main cameras I'm going to make a camera.

04:09.600 --> 04:11.280
Going to name it as camera one.

04:11.280 --> 04:12.540
Duplicate it.

04:13.020 --> 04:19.050
Camera two I'm going to bring them up over here as well as these two over here.

04:19.050 --> 04:24.300
And then let's take main camera and copy component.

04:25.200 --> 04:28.680
Go to these two cameras and paste component values.

04:29.320 --> 04:30.400
Very nice.

04:30.430 --> 04:32.410
Now there is something you need to know.

04:32.410 --> 04:37.960
There is this audio listener, and you're supposed to have only one audio listener in the game.

04:37.960 --> 04:39.850
That's what you're supposed to have.

04:39.850 --> 04:43.030
And we can remove the audio listener from the second one.

04:43.030 --> 04:48.130
But we cannot remove the audio listener from the first one, because when we enable split screen, we're

04:48.130 --> 04:50.770
going to disable main camera over here.

04:50.770 --> 04:55.330
And still we need to have at least one audio listener in the game.

04:55.330 --> 04:55.960
Okay.

04:55.960 --> 04:57.790
That's why we're going to keep it here.

04:57.790 --> 04:58.660
All right.

04:59.590 --> 05:02.170
So once again, camera one has audio.

05:02.170 --> 05:04.990
Listener camera two does not have audio listener.

05:05.350 --> 05:05.950
Cool.

05:05.980 --> 05:12.250
Also, I want to be sure that at the start of the game, main camera shows the view of the level and

05:12.250 --> 05:14.470
it has higher priority than these two.

05:15.190 --> 05:22.540
To do that, we can just take main camera and change depth to 0 or 1, and now it will have higher priority

05:22.540 --> 05:23.770
over the main camera.

05:23.770 --> 05:31.120
Another thing that we must do to enable split screen is to attach cameras to different cinemachine brains.

05:31.330 --> 05:35.980
Let's select this tool and add component of a Cinemachine brain.

05:37.240 --> 05:43.150
And you can see that both of them are connected to Cinemachine camera two, as well as the main camera

05:43.150 --> 05:44.170
over here.

05:47.880 --> 05:51.720
What we need to do is to make this camera be connected to this one.

05:52.910 --> 05:55.070
Camera one should be connected to the first one.

05:55.070 --> 05:58.220
Camera two should be connected to the second one like that.

05:58.220 --> 05:59.840
That is very easy to do.

05:59.870 --> 06:02.270
We just need to take cameras over here.

06:02.300 --> 06:05.540
Go to Cinemachine brain fine channel mask.

06:05.540 --> 06:07.280
Choose nothing.

06:07.280 --> 06:10.580
Then for the first one we should have channel one.

06:11.640 --> 06:14.430
For the second one, we should have channel two.

06:16.990 --> 06:17.920
Very nice.

06:17.920 --> 06:25.240
And for Cinemachine camera over here, we need to open the camera, find output channel, do nothing.

06:25.270 --> 06:27.310
Channel one for second.

06:27.310 --> 06:28.750
Camera nothing.

06:28.750 --> 06:29.800
Channel two.

06:29.830 --> 06:34.840
Now if you select this camera, you can see it is connected to Cinemachine camera two and this one is

06:34.840 --> 06:36.820
connected to Cinemachine camera one.

06:37.000 --> 06:39.640
Now let's go to the cinema screen over here.

06:39.640 --> 06:41.080
Output channel.

06:41.350 --> 06:42.340
And this is fine.

06:42.340 --> 06:46.450
We can leave it as it is on the main camera on Cinemachine brain.

06:46.450 --> 06:53.020
We need to find channel mask and remove channel one and remove channel two.

06:54.070 --> 06:55.630
So it should be like that.

06:55.720 --> 06:56.800
Very nice.

06:56.800 --> 07:00.700
Now this one is connected to this one to Cinemachine camera.

07:01.870 --> 07:06.880
Now this one connected to main Cinemachine camera one connected to the first cinemachine.

07:06.880 --> 07:09.670
Camera two connected to the second Cinemachine.

07:09.670 --> 07:10.540
Very good.

07:10.540 --> 07:14.710
Let's go to level camera and drag this over here.

07:15.630 --> 07:16.440
Like that.

07:17.590 --> 07:23.020
And also we want to disable main camera once we enable split screen.

07:24.210 --> 07:25.680
For that, I have an idea.

07:25.680 --> 07:30.390
We can just make a script object to disable.

07:32.440 --> 07:37.900
Inside of this script, I'm going to open Start Method and I'm going to do player manager dot instance

07:37.900 --> 07:41.680
objects to disable and this game object.

07:41.680 --> 07:43.930
So it will add itself to the list.

07:43.930 --> 07:47.530
And then player manager will disable this game object.

07:47.530 --> 07:50.440
And now we can just put the script on the main camera.

07:52.420 --> 07:54.310
Like sorry.

07:54.730 --> 07:55.690
Like that.

07:56.430 --> 07:57.450
Nice.

07:58.090 --> 07:58.960
Very nice.

07:58.960 --> 08:03.160
So we did almost everything that we need to do to make split screen work.

08:03.160 --> 08:06.790
And now we can set up this manually and it will work.

08:06.790 --> 08:08.680
But I don't want to set up it manually.

08:08.680 --> 08:12.340
I want player manager to be responsible for enabling split screen.

08:14.270 --> 08:15.260
And it will do that.

08:15.260 --> 08:21.470
You just need to know that when it creates a player to make a split screen, it needs to go to the player

08:21.470 --> 08:25.550
input component over here and assign camera in this field.

08:25.550 --> 08:27.680
So this one we need to do in the script.

08:28.040 --> 08:30.350
Let's go to player manager script.

08:35.580 --> 08:38.280
We need to go to add player method.

08:40.500 --> 08:41.910
Over here I'm going to do.

08:41.910 --> 08:46.080
If player input manager split screen is equals to true.

08:46.470 --> 08:53.940
Then we need to take the camera from split screen setup and assign it into component of a player input

08:53.940 --> 08:55.530
with the name New player.

08:55.740 --> 08:59.670
And the only problem is we don't have access to this variable yet.

08:59.670 --> 09:05.190
So we need to go maybe here and make a private level split screen setup.

09:08.140 --> 09:10.750
Split screen setup.

09:11.170 --> 09:12.820
And we need to get this component.

09:12.820 --> 09:17.380
And it should be found on a new level every time.

09:17.380 --> 09:19.990
So I'm going to go.

09:21.350 --> 09:22.280
Maybe here.

09:22.280 --> 09:24.770
This is our kind of start method.

09:24.920 --> 09:25.460
Right.

09:25.460 --> 09:33.530
And I'm going to do a split screen setup equal to find first object by type of a level split screen

09:33.530 --> 09:34.130
setup.

09:38.010 --> 09:39.120
Just like that.

09:39.390 --> 09:40.470
Very nice.

09:40.470 --> 09:41.340
Love it.

09:41.370 --> 09:45.480
Now let's go back over here and let's do this.

09:47.960 --> 09:51.920
New player camera equals to split screen setup.

09:51.920 --> 09:55.250
Main camera with an index of a new player number.

09:55.790 --> 10:02.090
Then we're going to take a split screen setup cinemachine camera with an index new player number and

10:02.090 --> 10:06.080
we're going to make it follow new player transform.

10:06.920 --> 10:07.940
And that's it.

10:08.600 --> 10:09.980
Let's save this.

10:09.980 --> 10:11.600
Let's go back to unity.

10:14.510 --> 10:19.580
Uh, we have split screen enabled over here, so it should be good.

10:20.000 --> 10:21.050
Let me try.

10:23.520 --> 10:24.990
Maybe I forgot something.

10:25.020 --> 10:26.880
So there is the camera view.

10:26.910 --> 10:28.860
It says press any key to join.

10:30.670 --> 10:32.200
I'm going to join the game.

10:32.200 --> 10:37.330
There is a first player and it says camera was not associated with the player.

10:37.330 --> 10:38.170
I know it's fine.

10:38.170 --> 10:41.320
Now let me join the second one and we have a split screen.

10:44.140 --> 10:46.240
First camera follows the first layer.

10:46.270 --> 10:48.610
Second camera follows the second layer.

10:48.640 --> 10:51.520
The only problem is that wait, it does not follow.

10:51.520 --> 10:52.480
Oh it does.

10:52.480 --> 10:53.110
Yeah.

10:53.110 --> 10:56.170
The problem is that player is not really in the center.

10:56.170 --> 10:59.470
So what we can do here is go to camera two.

11:03.470 --> 11:05.000
Open this over here.

11:05.000 --> 11:06.110
And.

11:10.510 --> 11:14.560
Take the X over here and make it 0.5 like that.

11:15.460 --> 11:16.600
Very nice.

11:18.520 --> 11:25.150
And I guess if we use a split screen setup for the game, maybe it is safer to remove audio listener

11:25.150 --> 11:25.930
from here.

11:25.930 --> 11:30.370
So I'm going to do that or I'll just disable it like that okay.

11:31.930 --> 11:32.830
Good.

11:33.600 --> 11:35.040
Uh, let me try again.

11:38.360 --> 11:40.640
So there is a single player in the game.

11:40.880 --> 11:42.290
Looks good to me.

11:43.730 --> 11:45.650
Let me check if camera follows it.

11:46.640 --> 11:48.380
Yeah, it follows the player.

11:48.410 --> 11:49.490
Very nice.

11:49.520 --> 11:54.890
Maybe we can disable this camera as well, because we don't need to, like, we don't need it to work

11:54.890 --> 11:56.000
for nothing.

11:56.000 --> 11:59.870
But I'll do that later and let me join the second player.

11:59.870 --> 12:02.840
And now we've got a split screen for the second player.

12:02.840 --> 12:05.420
And player is in the center as well as this one.

12:09.160 --> 12:12.460
Uh, if you like, you can make view a bit closer.

12:13.050 --> 12:14.040
Just over here.

12:14.040 --> 12:17.700
Choose lens type seven and maybe eight.

12:19.630 --> 12:21.070
Yeah, and it's a bit better.

12:21.070 --> 12:26.290
So now camera is following one player and second camera follows the second player.

12:26.290 --> 12:30.040
Now what happens if second player dies.

12:30.370 --> 12:31.300
This what happens.

12:31.300 --> 12:32.620
Well let me kill him.

12:32.830 --> 12:36.610
So when I kill this player the camera will become normal again.

12:36.610 --> 12:38.200
And I don't really like it.

12:38.200 --> 12:41.290
Especially because if you kill the first player.

12:42.390 --> 12:47.850
You will have split screen enabled anyway, so it's kind of not fair to fix it.

12:47.850 --> 12:49.380
We can go to.

12:54.130 --> 12:56.110
We can go to player manager.

12:56.350 --> 12:59.530
Choose set fixed number and set number two.

12:59.560 --> 13:02.620
Now we will always have split screen.

13:03.640 --> 13:04.630
Very good.

13:04.630 --> 13:05.950
And the camera's over here.

13:05.950 --> 13:08.260
You can do lens size eight.

13:09.290 --> 13:13.100
You can add object to disable on this component.

13:18.290 --> 13:20.300
And basically that's it.

13:22.510 --> 13:23.890
Let me try again.

13:27.110 --> 13:28.940
First layer, now second layer.

13:28.940 --> 13:30.800
And now we have split screen.

13:31.250 --> 13:33.710
And if first layer goes and.

13:34.750 --> 13:40.360
Gets him killed, then we still have a split screen and the camera will wait for you to join the game

13:40.360 --> 13:41.140
again.

13:42.130 --> 13:42.550
Ta da!

13:42.550 --> 13:43.540
We're here.

13:44.840 --> 13:46.910
So yeah, magic is done.

13:46.910 --> 13:48.980
I'm not sure if there is anything else to show.

13:49.010 --> 13:50.690
Maybe I'll take.

13:50.690 --> 13:51.890
Let me cancel it.

13:53.580 --> 13:54.930
Yeah, this one is.

13:54.930 --> 13:55.920
It's okay.

13:56.010 --> 14:00.060
Uh, let me go to asset prefab camera.

14:00.090 --> 14:02.430
I'm going to drag this over here.

14:02.460 --> 14:04.950
Maybe it would be even better to.

14:06.690 --> 14:07.170
Yeah.

14:07.170 --> 14:07.800
You know what?

14:07.800 --> 14:08.580
Let's.

14:09.600 --> 14:11.820
Take component from here.

14:12.030 --> 14:14.160
Put it here then.

14:14.160 --> 14:17.280
Let's take this component here.

14:17.880 --> 14:19.290
Put it here.

14:20.060 --> 14:23.510
And let's take this main camera.

14:24.530 --> 14:26.630
Copy it, paste it in, move it.

14:26.630 --> 14:30.650
Here I'm going to just do main camera like that.

14:30.650 --> 14:33.320
Or maybe camera zero.

14:34.750 --> 14:39.070
And now we can remove this game object from the scene because we don't need it anymore.

14:40.900 --> 14:42.850
And we can make a prefab.

14:43.880 --> 14:44.780
Camera.

14:44.780 --> 14:46.040
We can take this level.

14:46.040 --> 14:46.670
Camera.

14:46.670 --> 14:48.530
Change the name to um.

14:49.610 --> 14:52.340
Split screen setup.

14:53.890 --> 14:56.230
And we can drag it here as a prefab.

14:56.230 --> 15:00.760
And now if you want to have split screen in the camera, you just go to level.

15:00.760 --> 15:06.820
You remove camera manager, you remove level camera and you drag and drop these split screen setup and

15:06.820 --> 15:07.660
it will work.

15:07.660 --> 15:10.630
As for me, as of now I have a prefab.

15:10.630 --> 15:15.490
I'll just hold Ctrl Z to remove all of the changes that I did.

15:16.000 --> 15:16.750
All right.

15:24.100 --> 15:24.730
Very good.

15:24.730 --> 15:28.900
So I have the version of the game as it was before without a split screen.

15:28.900 --> 15:35.200
But prefab is here and if you want you can use it in your game okay in the script as well.

15:35.200 --> 15:39.490
It will work only if you enable split screen on the player manager, so it's fine.

15:39.730 --> 15:42.310
Okay, now I'm going to close everything.

15:42.310 --> 15:45.580
I'm going to save the project and let's go to the next video.
