WEBVTT

00:00.040 --> 00:02.400
We need to make our parallax effect.

00:02.400 --> 00:03.520
So let's do that.

00:03.520 --> 00:05.480
So we're going to create a script for it.

00:05.480 --> 00:09.760
So let's head over to this project tab then assets and then script folder.

00:09.760 --> 00:15.600
Let's right click there create and then Monobehaviour script and name that script to something like

00:15.600 --> 00:16.280
parallax.

00:16.280 --> 00:21.320
And I already have created a parallax script over here as you can see.

00:21.320 --> 00:24.240
So we need to attach this script to our background.

00:24.240 --> 00:26.880
So we're going to select all of our background in the hierarchy.

00:26.880 --> 00:30.040
So let's go to hierarchy then select this background.

00:30.040 --> 00:33.400
And we have BG one and BG two and BG three.

00:33.400 --> 00:36.720
So we're going to select all of the background by holding down shift.

00:36.720 --> 00:41.960
And let's drag this parallax script to this add component section in the Inspector.

00:41.960 --> 00:47.520
But make sure you don't attach the this script which is parallax one to the child one.

00:47.720 --> 00:52.080
So we just attach only this parent of BG as you can see.

00:52.080 --> 00:55.120
So this is the first background and this is the child one.

00:55.120 --> 00:58.160
And we haven't attached the script to the child one.

00:58.160 --> 01:04.000
So make sure you just attach the script to the parent backgrounds, so make sure you just do that.

01:04.000 --> 01:07.120
And let's open up our script by double clicking on it.

01:07.880 --> 01:09.120
So let's open that up.

01:09.120 --> 01:11.680
So what we're going to do now we're going to remove this comment.

01:11.680 --> 01:16.000
We don't need and we need a reference of our main camera.

01:16.000 --> 01:19.160
So we need a reference uh of our main camera.

01:19.200 --> 01:22.960
Then we're going to make a we're going to able to make our parallax effect.

01:22.960 --> 01:28.120
So what we basically want to do logically, we're going to move this background a little bit to the

01:28.120 --> 01:28.880
right side.

01:28.880 --> 01:32.040
So it's gonna seem that parallax are basically having.

01:32.040 --> 01:36.280
So we're going to move the first background a little a little bit uh, fast.

01:36.280 --> 01:41.920
You can simply say, uh, and which will be far from our main camera, we're going to make a, we're

01:41.920 --> 01:46.480
going to move that background a little bit slowly as compared to the first one.

01:46.480 --> 01:50.280
So it's going to seem like, uh, there is a parallax effect.

01:50.280 --> 01:52.240
So basically that is the logic.

01:52.240 --> 01:56.440
So let's open up our parallax effect by double clicking on it.

01:56.440 --> 02:00.040
And what we need, we need a reference of our main camera first.

02:00.040 --> 02:03.120
So let's create a variable for our main camera.

02:03.120 --> 02:06.880
And let's make it public so we can adjust underneath our inspector.

02:07.000 --> 02:11.160
So the component we're looking for or the GameObject we're looking for is a camera.

02:11.160 --> 02:16.360
So we're going to type camera I guess we need to type camera yes camera.

02:16.360 --> 02:19.040
And we can call it something like main camera.

02:19.040 --> 02:21.360
So let's call it main camera.

02:21.360 --> 02:24.440
Or we can simply call it camera as well.

02:24.720 --> 02:32.320
And also we can we need some uh some or other things like the start position, all of these, uh, all

02:32.320 --> 02:35.520
of this background start position or the current position.

02:35.520 --> 02:41.200
So we're gonna grab the start position of all of this background, basically the first one and which

02:41.200 --> 02:44.120
one is far away, as well as the middle one.

02:44.160 --> 02:49.840
And also we need a length of this, uh, background, all of this background, uh, for the first one,

02:49.840 --> 02:53.440
as well as the last one as well as the middle one.

02:53.440 --> 02:59.520
So we're gonna grab the start pose of all of this background as well as the length of it.

02:59.520 --> 03:01.150
So let's go to script now.

03:01.150 --> 03:03.710
And we just getting in green underline.

03:03.710 --> 03:07.550
And we able to see that basically what we have to do.

03:07.550 --> 03:10.790
We need to type this new over here and that's it.

03:10.790 --> 03:12.550
So you need to type this new.

03:12.590 --> 03:15.710
Basically there is a already called variable camera.

03:15.710 --> 03:18.510
So that's why it's just conflicting the error.

03:18.510 --> 03:22.350
So we just need to type this new and it's uh okay.

03:22.630 --> 03:29.830
And the some and we also need two more things, which is the start pose of each of those backgrounds

03:29.830 --> 03:32.470
as well as the length of those background.

03:32.470 --> 03:35.990
And it doesn't need to be public so we can make it private instead.

03:35.990 --> 03:38.950
So we're going to make it private and that will be float.

03:38.950 --> 03:42.430
And we can simply call this one to something like Start Pose.

03:42.470 --> 03:45.270
Or you can simply say start pose or background.

03:45.270 --> 03:49.550
And the second thing we need or need is the length of each background.

03:49.550 --> 03:50.670
So we're gonna grab it.

03:50.670 --> 03:54.150
So we're going to make this one as well a private that will be float.

03:54.150 --> 03:56.950
And we can call this one something like length.

03:57.710 --> 04:00.790
I guess this should be the correct spelling.

04:01.110 --> 04:07.150
I'm really apologize if it's not let and we're gonna move over to this start function by now.

04:07.150 --> 04:13.470
In the start of the game, we're just gonna grab the length as well as the start position of those backgrounds.

04:13.470 --> 04:20.430
So what we're going to do, we're going to type this start post equal to transform dot position and

04:20.430 --> 04:21.190
then x.

04:21.190 --> 04:23.150
So we're going to take the x axis.

04:23.150 --> 04:28.230
So basically what we're doing we're basically going to each of these background this transform then

04:28.270 --> 04:29.990
accessing this x position.

04:29.990 --> 04:36.550
And we storing this x position of all each of this background into this start pose variable.

04:36.590 --> 04:38.350
As you can see we created.

04:38.350 --> 04:43.190
So we're just taking the x axis of each of each of those background.

04:43.190 --> 04:47.550
And we just storing the position in the x axis to this start pose.

04:47.750 --> 04:51.270
And also we need to grab the length of our background.

04:51.270 --> 04:52.150
So let's do that.

04:52.150 --> 04:54.390
So we're going to do length equal.

04:54.710 --> 05:00.990
So we're going to use this this dot get component this dot can component.

05:00.990 --> 05:04.310
And the component we're going to look for is a sprite renderer.

05:04.310 --> 05:09.030
So we will move over to sprite renderer component then make first bracket.

05:09.030 --> 05:12.030
And then we need to use this bounds to get the size.

05:12.030 --> 05:13.590
And then we're going to use dot.

05:13.630 --> 05:15.430
And then we're going to type size.

05:15.430 --> 05:21.190
And then we're going to take the x size or x length in the x or x axis length.

05:21.190 --> 05:22.590
You can simply call it.

05:22.590 --> 05:27.110
And we're going to put and make sure you just uh close that up with some colon.

05:27.110 --> 05:28.550
So what we basically doing.

05:28.550 --> 05:31.230
We just get we using this dot get component.

05:31.230 --> 05:33.350
Basically it's just referencing itself.

05:33.350 --> 05:39.790
And we're just going over to this sprite renderer component, each of this background sprite renderer.

05:39.790 --> 05:45.590
And then this reference of this sprite renderer which is getting the size of each of this background

05:45.590 --> 05:47.110
in the x axis.

05:47.110 --> 05:51.630
So basically we're just getting the size of each of this background in the x axis.

05:51.630 --> 05:56.390
And we're storing that size into this length variable as you can see.

05:56.390 --> 06:02.350
So we're just going to spriterenderer then bounce and then size, and we're just getting the x size

06:02.590 --> 06:03.990
in the x axis size.

06:03.990 --> 06:06.510
And we're taking the size each of those background.

06:06.510 --> 06:09.710
And we're storing in this length as you can see.

06:09.870 --> 06:14.990
So now we can see we have start position of each of those background as well as the length.

06:15.110 --> 06:17.510
And we are ready to make the parallax.

06:17.670 --> 06:20.870
So firstly we're going to create we're gonna create the illusion.

06:20.870 --> 06:23.550
Basically we're just gonna make a main camera.

06:23.590 --> 06:31.230
Just uh, basically uh, you can simply say, uh, we're just gonna take, we're gonna take our main

06:31.230 --> 06:36.230
camera and we're going to move it a little bit further away, or we're going to take all of this background

06:36.230 --> 06:41.550
and we're going to multiply with some number, uh, to just move it, uh, all of this background to

06:41.590 --> 06:48.030
the right side a little bit, and we're going to multiply with different speed, uh, or different numbers.

06:48.030 --> 06:50.070
So it's going to make the parallax effect.

06:50.070 --> 06:51.350
So let's do that.

06:51.350 --> 06:53.070
So I'm going to move over to script.

06:53.270 --> 06:58.790
And instead of grabbing the main camera as you can see we're going to grab the this camera parent game

06:58.910 --> 06:59.390
Object.

06:59.430 --> 07:04.310
So basically we need a reference of this camera parent game object instead of the main camera.

07:04.350 --> 07:06.950
You can take the main camera reference as well.

07:06.990 --> 07:11.950
It's not gonna uh it's it's basically not much difference.

07:11.950 --> 07:15.590
But I'm going to take this camera parent game object reference.

07:15.630 --> 07:18.270
Basically we need a reference of this game object.

07:18.270 --> 07:20.070
Then we can make that happen.

07:20.070 --> 07:22.150
So let's go to script one more time.

07:22.150 --> 07:27.670
And instead of grabbing the main camera reference I'm going to grab the camera parent game Object reference.

07:27.670 --> 07:31.870
So we're going to make it public so we can access it underneath our inspector.

07:32.190 --> 07:37.030
Uh, and that is a game object we're looking for basically that camera parent game object.

07:37.030 --> 07:40.110
It's all itself or a whole game object.

07:40.110 --> 07:42.830
So that's why we need to type this, which is game object.

07:42.830 --> 07:45.110
And we have to name it what we want to call.

07:45.110 --> 07:48.110
So I'm going to call it something like camera something like that.

07:48.110 --> 07:50.310
And we're going to close that up with semicolon.

07:50.310 --> 07:53.470
So we as you can see we're just getting a problem.

07:53.510 --> 07:56.070
Or we can simply call it cam instead.

07:56.070 --> 07:57.830
So it's just going to be go on.

07:57.830 --> 08:03.430
Or you can just put it in front of this new and it's gonna go and we're going to press down control

08:03.470 --> 08:05.510
S in order to save our script.

08:05.510 --> 08:11.150
And let's move over to unity by now, basically, we just want to grab the reference first and then

08:11.150 --> 08:12.230
we're going to do that.

08:12.550 --> 08:17.230
So just wait for it to compile and you will see uh, underneath our, uh.

08:17.230 --> 08:20.830
Sorry, we have done a mistake, I guess.

08:20.870 --> 08:22.470
No, no no, sorry, sorry.

08:22.750 --> 08:29.790
Uh, basically we can see a follow script, and we do know we just attach the script to this background.

08:29.830 --> 08:31.030
I'm really apologize.

08:31.030 --> 08:34.710
So we're going to select all of this background by holding down shift in the hierarchy.

08:35.190 --> 08:39.230
And let's go to Inspector Sprite Renderer then play parallax script.

08:39.230 --> 08:45.790
As you can see underneath our parallax script we can see GAM and it says none GameObject basically empty.

08:45.830 --> 08:49.150
So we're going to take our camera parent game object or the main camera.

08:49.190 --> 08:51.870
You can simply say we're going to take that sorry.

08:51.910 --> 08:55.030
We're going to take that and we're going to drag it into the slot.

08:55.070 --> 08:59.940
And now as you can see we have a reference of this camera parent game object.

09:00.380 --> 09:06.140
Or you can simply say that we have camera reference and now we are ready to do that.

09:06.140 --> 09:10.740
So let's open up our players parallax script script by double clicking on it.

09:10.740 --> 09:13.180
And let's move over to this update function.

09:13.180 --> 09:15.060
So in the update function we're going to do.

09:15.220 --> 09:17.300
So we're going to uh what we will do.

09:17.300 --> 09:20.500
We will take our camera position of the camera position.

09:20.500 --> 09:22.420
And we're going to multiply with something.

09:22.420 --> 09:25.820
So it's gonna so it's gonna to the right side basically.

09:25.820 --> 09:29.300
So it seems like main camera just going to the right side.

09:29.300 --> 09:33.620
Or we're going to create the illusion in order to make the parallax effect.

09:33.620 --> 09:36.060
So what we will do, we will move over to script.

09:36.060 --> 09:39.460
And over here we're going to go to Camera Cam Game Object.

09:39.500 --> 09:40.260
Sorry cam.

09:40.300 --> 09:41.900
And we have the reference.

09:41.940 --> 09:47.820
As you can see underneath our parallax script we have the camera parent reference game object.

09:47.820 --> 09:49.300
So we will go to that.

09:49.300 --> 09:51.540
And then we're going to access the transform.

09:51.540 --> 09:55.820
Then we're going to access the position and we will access the x axis.

09:55.820 --> 09:58.740
And we're going to multiply with uh some unit.

09:58.740 --> 10:02.500
So let's create another parameter in order to make the parallax.

10:02.500 --> 10:09.140
Basically, we will move over to top of our class and we're going to make another variable for our parallax

10:09.180 --> 10:13.860
or how much parallax we basically want to uh, we basically want.

10:14.060 --> 10:21.380
So let's create a public float and we can call this one to something like parallax, uh, parallax.

10:21.860 --> 10:24.580
And uh, I'm going to close that up with semicolon.

10:24.820 --> 10:31.540
And with this parallax, we can, uh, adjust this one underneath our script as well.

10:31.540 --> 10:33.580
So I'm not going to give a default value.

10:33.580 --> 10:37.140
I'm going to adjust underneath my parallax script.

10:37.140 --> 10:42.620
And now what we're going to do, we're going to multiply x position of our main camera with this parallax.

10:42.780 --> 10:46.540
So let's multiply that and we're going to close that up semicolon.

10:46.540 --> 10:48.860
And now we're going to store this result basically.

10:49.300 --> 10:52.660
Firstly we're just taking our main camera in the x position.

10:52.660 --> 10:55.220
And then we just multiplying with this parallax.

10:55.220 --> 10:59.060
So the result we're going to store into another float parameter.

10:59.060 --> 11:03.060
So let's create a float and we can call this one to something like distance.

11:03.060 --> 11:05.580
Or you can simply call it parallax effect.

11:05.900 --> 11:07.420
So as you can see.

11:07.580 --> 11:09.580
So firstly we're just going over to camera.

11:09.580 --> 11:16.260
And then basically we're just going over to this camera parent game object and then accessing this transform

11:16.260 --> 11:18.220
then accessing this x position.

11:18.220 --> 11:19.540
And we just multiply.

11:19.780 --> 11:25.220
Multiplying this x position some unit basically as a parallax as you seen.

11:25.220 --> 11:29.380
So it's going to make or just going to create the illusion of parallax.

11:29.700 --> 11:31.420
So let's go to script now.

11:31.740 --> 11:38.940
And then we just taking that result and storing in this float distance parameter as you can see.

11:38.980 --> 11:43.260
And after that we also need to move our background as well.

11:43.260 --> 11:44.540
So we just multiply it.

11:44.540 --> 11:47.660
So we also need to move our background as well.

11:47.660 --> 11:51.180
So what we're going to do we're going to set transform dot position.

11:51.180 --> 11:56.660
So transform dot basically transform dot position means the current position each of this background.

11:56.660 --> 12:03.820
And we're going to set the set the position current position of each of those background are what we

12:03.820 --> 12:04.140
will do.

12:04.140 --> 12:06.860
We will set equal to a new vector three.

12:07.020 --> 12:08.700
Why are we using this vector three?

12:08.700 --> 12:13.340
Because this vector three is going to have x axis, y axis and the z axis.

12:13.340 --> 12:19.300
And we do know this transform dot position also has x axis y axis and the z axis.

12:19.300 --> 12:22.900
So that's why we need to set same variable type.

12:23.100 --> 12:27.740
So this vector three is just going to have x axis y axis and the z axis.

12:27.940 --> 12:31.860
So we don't want our parallax effect in this z axis.

12:31.860 --> 12:37.380
So what we can simply do we can just put zero f in the z axis.

12:37.380 --> 12:41.380
Or we can simply pass a transform dot position.

12:41.420 --> 12:47.820
Dot z basically means current position of each of those background in this z axis itself.

12:47.820 --> 12:51.220
So we not doing at all anything in this z axis.

12:51.220 --> 12:53.740
And we're going to do the same thing in the y axis.

12:53.740 --> 12:58.460
And we only want that parallax effect having two in the x axis.

12:58.500 --> 13:01.380
We don't want in the y as well as in the Z.

13:01.420 --> 13:04.700
But if you have a platformer game, then you can just do.

13:04.740 --> 13:07.580
Or you can play with y axis as well.

13:07.580 --> 13:09.620
It's basically totally up to you.

13:10.060 --> 13:11.540
So let's go to a script now.

13:12.020 --> 13:16.540
And what we're going to do in the Y, we're going to set transform dot position.

13:16.580 --> 13:23.500
Dot y basically means current position in the y axis of each of each of those background itself.

13:23.820 --> 13:29.220
And in the x axis we do know we just want our parallax effect to happen.

13:29.220 --> 13:35.980
So what we will do we will type transform transform dot position sorry not transform dot position.

13:35.980 --> 13:42.020
Basically we do know we we just grabbed the start position of each of this background in the x axis

13:42.180 --> 13:43.260
as you can see.

13:43.260 --> 13:46.220
So we're going to pass as a first argument in the x axis.

13:46.220 --> 13:47.660
Firstly we're going to pass start.

13:47.660 --> 13:52.100
First means the start position of each of this background.

13:52.100 --> 13:55.620
And top of this top of this we're going to add the illusion.

13:55.620 --> 13:57.970
So we're going to use this plus icon.

13:57.970 --> 13:59.970
And then we're going to add this distance.

13:59.970 --> 14:02.490
Basically we just move it a little bit away.

14:02.490 --> 14:03.970
So we're going to take this distance.

14:03.970 --> 14:08.450
So start pose means our start position of each of this background.

14:08.450 --> 14:14.610
And top of this we're going to add the illusion or distance parameter that we created for illusion.

14:14.610 --> 14:16.850
So we're going to add top of this distance.

14:16.850 --> 14:18.890
As you can see now it's fine.

14:19.010 --> 14:23.330
Start pose basically means the start position of each of those background.

14:23.330 --> 14:26.570
And top of that we just added this distance parameter.

14:26.730 --> 14:29.010
And basically we're just taking our main camera.

14:29.010 --> 14:34.490
And we multiplying means the main camera will go to the right direction a little bit away.

14:34.530 --> 14:41.330
And we're taking that change and then adding top top of our start position as you can see.

14:41.330 --> 14:44.570
So I'm going to press Ctrl S in order to save our script.

14:44.570 --> 14:46.690
And I'm going to move this one here.

14:47.130 --> 14:48.570
And this one should be here.

14:48.570 --> 14:52.770
And we're going to press Ctrl S in order to save our script.

14:54.210 --> 14:56.090
Let's go to unity by now.

14:57.330 --> 15:03.090
And also we need to basically, uh, make, uh, our backgrounds endless.

15:03.290 --> 15:06.290
But before we do, let's have a look on this.

15:06.330 --> 15:07.890
What we have done so far.

15:07.890 --> 15:09.530
We're going to check that out.

15:14.810 --> 15:15.850
So just wait.

15:16.130 --> 15:19.130
And now what we're going to do we're going to select all of this background.

15:19.130 --> 15:22.250
So this is our BG one or the first background.

15:22.250 --> 15:25.410
And it's pretty much close to our main camera.

15:25.410 --> 15:33.130
So that's why we want this background move to a little bit uh fast as compared to which is far away

15:33.130 --> 15:35.290
from our main camera.

15:35.290 --> 15:36.530
So this is the big one.

15:36.530 --> 15:41.010
So I'm going to make the parallax effect something like, uh, 0.1.

15:41.010 --> 15:46.090
Or we can simply do something around 0.5, and we're going to select the middle one.

15:46.090 --> 15:52.130
And this middle one should, uh, go, uh, a little bit slow as compared to the close one.

15:52.130 --> 15:55.370
So I'm going to make it something like so this is 1.5.

15:55.370 --> 16:02.730
So I'm going to make it something point three and the which one is further away from our main camera.

16:02.730 --> 16:09.050
And we want that background to move slowly as compared to boot of this, which is close to our main

16:09.050 --> 16:09.730
camera.

16:09.730 --> 16:13.970
So we're going to select our BG three and we're going to make the parallax something like 0.1.

16:13.970 --> 16:16.690
And now we are ready to play our game.

16:16.690 --> 16:19.610
But before we do let's select our parent game object.

16:19.610 --> 16:25.250
So in our case background and make sure you go to Inspector Overrides and then click on Apply All.

16:25.250 --> 16:28.290
So the change is going to be saved into prefab as well.

16:28.290 --> 16:29.850
And now we can play our game.

16:29.850 --> 16:32.890
And let's have a look on our parallax effect.

16:32.890 --> 16:35.130
So let's click on this play button in the top.

16:39.890 --> 16:41.970
And let's have a look on this.

16:45.250 --> 16:50.250
So as you can see as soon as we started our game parallax does happening.

16:50.250 --> 16:54.010
But the problem is that parallax just going in the opposite direction.

16:54.010 --> 16:54.330
It.

16:54.330 --> 16:56.290
So it should move to the left.

16:56.290 --> 16:57.690
So we're going to get out of play mode.

16:57.690 --> 17:03.490
So what we can basically do, we can just put minus uh to this point five.

17:03.490 --> 17:08.730
So we can simply put minus -0.5 or -0.5.

17:08.850 --> 17:12.930
So the parallax is just going to happen in the left side or behind.

17:13.250 --> 17:14.890
So we're going to take this one.

17:14.890 --> 17:16.490
And we're going to put minus.

17:16.690 --> 17:18.250
And we're going to select our third.

17:18.250 --> 17:21.450
And we're going to make this one minus as well.

17:21.450 --> 17:23.130
And now let's go to backgrounds.

17:23.130 --> 17:24.370
Let's go to overrides.

17:24.370 --> 17:28.490
Click on Apply All and let's click on this play button in the top.

17:28.490 --> 17:31.010
And you will see the parallax right away.

17:31.250 --> 17:33.050
Right away the game start.

17:38.490 --> 17:41.770
And now we can see the parallax just happening.

17:41.770 --> 17:44.690
But the problem is that it seems like too much fast.

17:44.690 --> 17:46.850
So we can make a little bit less.

17:46.850 --> 17:48.490
So let's get out of play mode.

17:48.490 --> 17:50.410
And I'm going to select my first background.

17:50.410 --> 17:54.370
And I'm going to do it something like uh .08.

17:54.850 --> 17:57.050
So let's do .08.

17:57.250 --> 17:58.690
And I'm going to select this one.

17:58.690 --> 18:01.890
And I'm going to make -0.05.

18:02.090 --> 18:03.850
And I'm going to select the further one.

18:03.850 --> 18:13.210
And I'm going to make it -0 -0.0 something like uh one I guess one.

18:13.210 --> 18:15.490
And this is five, this is eight.

18:15.490 --> 18:17.050
And now it seems good.

18:17.090 --> 18:20.370
So let's click on this play button in the top to play our game.

18:20.690 --> 18:22.890
And let's have a look on this.

18:23.330 --> 18:27.490
But uh, play around with those values and you can get a perfect number.

18:29.050 --> 18:36.130
And now we can see the parallax is now totally fine because our player is speed a little bit fast.

18:36.130 --> 18:40.290
So that's why it's just looking a little bit weird and that's it.

18:40.290 --> 18:41.850
So let's get out of play mode.

18:41.890 --> 18:45.730
And let me show you one thing that we have forgot to do that.

18:45.730 --> 18:48.450
So let's click on this play button to play our game.

18:48.810 --> 18:50.810
And let's take a look on this.

18:58.440 --> 19:02.320
Now let's play our game and we are jumping.

19:02.360 --> 19:03.480
As you can see.

19:04.840 --> 19:06.840
And we just jumping a lot.

19:14.920 --> 19:16.440
So I'm gonna pause my game.

19:16.440 --> 19:20.560
As you can see the background just getting end over here.

19:20.560 --> 19:22.080
And we don't want that.

19:22.080 --> 19:25.600
And we want our backgrounds to loop forever.

19:25.760 --> 19:29.480
It's gonna seem like, uh, backgrounds just never ending.

19:29.480 --> 19:32.040
So what we have to do, we need to skip that.

19:32.040 --> 19:34.240
So let's get out of play mode and let's do it.

19:34.240 --> 19:36.160
So we're gonna open up our script.

19:36.280 --> 19:40.960
And firstly, we need to grab the actual position of each of this background.

19:40.960 --> 19:42.280
Then we can do that.

19:42.280 --> 19:44.800
So we're going to open up our parallax effect.

19:44.800 --> 19:46.600
And let's do it over here.

19:46.920 --> 19:50.600
So what we will do we will go to cam or camera.

19:50.640 --> 19:55.080
You can simply say we just moving over to this camera parent game object.

19:55.080 --> 19:57.760
And we're going to access the X position.

19:58.160 --> 20:03.560
So we're going to firstly we will go to transform then position and then X.

20:03.560 --> 20:07.240
And we're going to multiply this one minus parallax effect.

20:07.240 --> 20:10.640
So we just made the parallax effect sorry one.

20:10.640 --> 20:12.920
So we need to we're going to do inside this bracket.

20:12.920 --> 20:15.520
So make first bracket and we're going to minus.

20:15.520 --> 20:20.000
So we need to use this one minus the parallax effect that you included.

20:20.240 --> 20:21.960
So we're going to type our parallax.

20:21.960 --> 20:24.000
And let's close that up with semicolon.

20:24.240 --> 20:27.480
So basically we're just going over to main camera then position.

20:27.480 --> 20:29.400
And we accessing the x position.

20:29.400 --> 20:33.120
And we just multiplying whatever one minus parallax effect.

20:33.120 --> 20:35.640
So it's going to give our actual position.

20:35.640 --> 20:38.400
And we're going to store it into a temp variable.

20:38.400 --> 20:40.040
So let's store the result.

20:40.040 --> 20:41.440
So we're going to use float.

20:41.440 --> 20:44.680
And we can call this temp or short for temporary.

20:44.720 --> 20:46.520
And let's set equal to this.

20:46.520 --> 20:49.000
So this is going to be the actual position.

20:49.000 --> 20:53.160
And now we're going to use if condition in order to just grab it.

20:53.160 --> 20:57.320
So we're going to use this if and make first bracket packet and some curly brackets.

20:57.360 --> 20:59.320
So what we want to check over here.

20:59.320 --> 21:00.160
We're going to check.

21:00.640 --> 21:05.600
So we will check if ten if ten is greater than start post.

21:05.720 --> 21:10.120
So start post basically means our start position of each of those program.

21:10.120 --> 21:12.600
And top of that we're going to add the length.

21:12.640 --> 21:19.600
So temp if it's greater than start post plus Len and temp basically means the actual position and length.

21:19.760 --> 21:23.240
And if it's greater than start post plus length.

21:23.360 --> 21:28.520
So basically over here somewhere over here we can have.

21:28.560 --> 21:34.040
So what we want we just want to attach one background over here top of this one.

21:34.040 --> 21:40.560
So that's why if the temp is greater than a if that is the case then we're gonna take our start post

21:40.600 --> 21:41.400
our background.

21:41.400 --> 21:43.760
And top of that we're going to add one more background.

21:43.760 --> 21:46.880
So we're going to add top of plus equal the length.

21:46.920 --> 21:48.160
So we're going to add length.

21:48.160 --> 21:50.280
And let's close that up with semicolon.

21:50.280 --> 21:53.160
So temp basically means the actual position and the length.

21:53.160 --> 21:58.640
And we're checking if it's greater than start post plus length and how we can just get it tame.

21:58.680 --> 22:03.840
Basically, we're just taking our main camera and then multiplying one minus parallax effect.

22:03.880 --> 22:06.320
Basically the parallax that we included.

22:06.320 --> 22:10.960
So we're just subtracting and then and we don't know subtracting.

22:11.000 --> 22:18.560
We're just getting the actual temp or actual length of background and the and the start position of

22:18.560 --> 22:19.400
our background.

22:19.400 --> 22:25.960
And we're checking if that is greater than start post plus length basically means the length of our

22:25.960 --> 22:26.480
background.

22:26.480 --> 22:31.240
And the top of we're just adding the start post start post plus length.

22:31.280 --> 22:33.760
So if it's greater than greater than.

22:33.800 --> 22:34.800
As you can see.

22:34.800 --> 22:38.880
So we just taking our start position of each of those background.

22:38.880 --> 22:42.880
And top of that we just adding one more background as you can see.

22:42.880 --> 22:46.080
So at start post plus equal length as you can see.

22:46.120 --> 22:49.840
And now we're going to press down Ctrl S in order to save our skip.

22:49.840 --> 22:57.400
And if you uh, if you just little bit uh, something like confuse Then I'm gonna have a video in the

22:57.400 --> 23:00.240
resources about parallax deeply.

23:00.240 --> 23:03.600
If you want to check that out, you can go and check it.

23:03.600 --> 23:10.400
So you're gonna get I'm gonna give two videos, link in the resources about parallax effect and the

23:10.400 --> 23:12.920
camera following like that.

23:13.040 --> 23:20.000
You can go and check that out if you just want to more want to just get it more deeply if you just want

23:20.000 --> 23:20.960
to do that.

23:20.960 --> 23:24.000
So for now let's click on this play button and let's have a look.

23:24.000 --> 23:31.000
If the parallax effect and the background just never getting ending A working perfectly or not.

23:31.000 --> 23:33.080
So we're going to take a look on that.

23:34.040 --> 23:39.840
So as soon as the game started we are running and we can see the parallax effect as well.

23:41.000 --> 23:43.080
Sorry I'm really sorry.

23:43.120 --> 23:50.120
And this should as you can see, as soon as the camera is over here or the camera button, we can see

23:50.160 --> 23:56.880
one more background just getting on top of this one previous one As you can see.

23:56.920 --> 24:01.240
And pretty much let's get out of play mode and we're going to test with our player.

24:01.560 --> 24:03.120
So I'm going to take my player.

24:03.120 --> 24:05.600
So let's select the player GameObject in the hierarchy.

24:05.600 --> 24:08.800
And we're going to press down F in order to focus on it.

24:08.800 --> 24:13.440
And I'm going to move this up player somewhere around here.

24:13.440 --> 24:17.040
And let's click on this play button in the top to play our game.

24:26.960 --> 24:30.160
And we can see this is pretty much fine by now.

24:35.920 --> 24:39.440
I guess it's gonna work perfectly, but it's not working.

24:39.440 --> 24:42.960
So we basically need to adjust our background perfectly.

24:42.960 --> 24:44.640
So let's get out of play mode.

24:44.800 --> 24:46.600
And we're going to select our background.

24:47.040 --> 24:49.000
And let's select the child one.

24:49.000 --> 24:53.200
And let's take a look if it's just perfectly fitting or not.

24:53.240 --> 24:59.350
So for now I'm going to select my BG three or background three, and let's select the duplicate one.

24:59.350 --> 25:03.390
And we're going to take a closer look by scrolling our mouse.

25:03.390 --> 25:05.390
And we need to feed it perfectly.

25:05.750 --> 25:11.830
So I'm gonna take my duplicate and I'm going to move a little bit okay.

25:11.950 --> 25:14.150
So we need to move this.

25:17.590 --> 25:25.670
So we're going to make it something like two five so we can move it

25:25.670 --> 25:33.150
(353) 538-3939.

25:33.150 --> 25:34.990
Or we can simply do four.

25:35.270 --> 25:37.070
Basically we need to adjust that

25:37.310 --> 25:43.750
51405.

25:45.110 --> 25:47.870
So I guess four seems perfect number.

25:48.310 --> 25:51.910
So 100 is a 102.4.

25:52.230 --> 25:54.910
So we're going to do the same thing with this BG pg2.

25:54.950 --> 25:59.230
Let's put it 100, uh, 2.4.

25:59.910 --> 26:06.710
And we're going to do the same thing with this one, this background, and we're going to put 102.4.

26:07.350 --> 26:09.430
And it should be perfect by now.

26:09.590 --> 26:12.310
But let's take a look before we do.

26:12.310 --> 26:14.510
So we're going to go to overrides in the inspector.

26:14.510 --> 26:16.070
Let's click on this apply all.

26:16.390 --> 26:19.630
And we can just focus that by hitting F keyword.

26:19.630 --> 26:23.590
And let's click on this play button in the top to play our game.

26:30.550 --> 26:32.830
And it should be fine.

26:37.390 --> 26:38.030
Sorry.

26:38.270 --> 26:40.030
So let's take a look like this.

26:40.310 --> 26:41.430
It should be fine.

26:41.950 --> 26:45.030
So we're still getting a little bit weird.

26:46.710 --> 26:48.150
So we need to adjust that.

26:48.150 --> 26:50.590
Basically we need to adjust our background.

26:50.590 --> 26:54.950
So make sure you just adjust your background perfectly and it's going to be perfect.
