WEBVTT

00:00.080 --> 00:03.920
Let's create a script in order to trigger that shape parameter.

00:03.920 --> 00:06.280
So we're going to create a script for that.

00:06.280 --> 00:11.480
So let's head over to this project tab, then assets then scripts folder.

00:11.520 --> 00:12.560
Let's head over to that.

00:12.560 --> 00:16.080
Let's right click there create and then Monobehaviour script.

00:16.520 --> 00:21.640
Because we're going to attach this script to our game object in hierarchy and name it to something like

00:21.640 --> 00:22.400
Camera check.

00:22.440 --> 00:28.880
I already have created a camera check script and you can see it over here, as you can see.

00:28.880 --> 00:34.480
So we're going to attach this script to any game object of our hierarchy in our hierarchy.

00:34.480 --> 00:37.440
Or we can simply select this camera parent.

00:37.440 --> 00:41.120
Or we also can create a game object for that.

00:41.120 --> 00:42.320
So we're going to create that.

00:42.320 --> 00:43.960
So let's go over to hierarchy.

00:44.200 --> 00:46.320
Let's right click there or hit this place.

00:46.360 --> 00:48.600
Sorry I'm going to enable this one.

00:48.600 --> 00:50.600
So let's go to Inspector and check it.

00:50.920 --> 00:52.320
And let's go to hierarchy.

00:52.480 --> 00:54.320
Right click or hit this plus icon.

00:54.320 --> 00:56.600
And we're going to create an empty game object.

00:56.600 --> 01:00.970
And I'm going to name this game object as the script name something like camera check.

01:01.130 --> 01:02.970
So I'm going to call it camera check.

01:04.250 --> 01:04.770
Sorry.

01:05.050 --> 01:06.730
Camera check.

01:07.610 --> 01:09.170
Camera shake.

01:09.570 --> 01:11.010
Let's call it camera check.

01:11.050 --> 01:12.290
And let's go to transform.

01:12.290 --> 01:13.730
Let's reset the transform.

01:13.730 --> 01:15.850
And I'm going to select my camera check script.

01:16.050 --> 01:16.330
Sorry.

01:16.370 --> 01:17.650
Camera check game object.

01:17.650 --> 01:21.370
And I'm going to drag it all the way to the top in hierarchy.

01:21.530 --> 01:25.770
And let's select the script and let's drag it over to this Add Component section.

01:25.770 --> 01:29.210
And let's double click this to open it up in Visual Studio.

01:29.210 --> 01:31.610
So I'm going to remove this start function.

01:31.610 --> 01:36.730
And also this uh comment from here I'm going to remove that instead.

01:36.730 --> 01:41.410
What we basically need we need a reference of that animator component.

01:41.410 --> 01:47.330
So if we moved over to camera parent then main camera and then move over to animator tab, we can see

01:47.330 --> 01:51.050
the animation is created inside this main camera.

01:51.050 --> 01:54.570
And if we select our main camera then go over to Inspector.

01:54.570 --> 02:00.450
We can see an animator component added once we created this animation clip, this check, and the ideal

02:00.450 --> 02:00.890
one.

02:00.890 --> 02:06.050
So we need a reference of this animator component, uh, in this main camera.

02:06.050 --> 02:10.890
Then we can just trigger this check parameter in animator tab, as you can see.

02:10.890 --> 02:15.250
So we need a reference of this animator component of this main camera.

02:15.250 --> 02:18.770
So let's open up our camera check split by double clicking on it.

02:18.770 --> 02:20.690
And let's go to top of our class.

02:20.690 --> 02:24.210
And let's make a serialized file a serialized file.

02:24.650 --> 02:28.610
So let's make a serialized file private, uh, private.

02:28.610 --> 02:34.570
And we're going to call it, uh, basically we need the reference of that animator component so we can

02:34.570 --> 02:38.010
simply pass animator or the component that we're looking for.

02:38.050 --> 02:39.970
And I'm going to call it animator.

02:39.970 --> 02:42.010
And let's close that up with semicolon.

02:42.050 --> 02:48.650
It's a if you just a bit or worry it about this serialized field, then you can check the chapter where

02:48.970 --> 02:52.290
I have explained how you can make your code clean.

02:52.690 --> 02:57.420
Uh, so you can just check the previous Years, a chapter and the lectures of this.

02:57.740 --> 03:02.380
So now we're going to save by control S in order to save our script.

03:02.380 --> 03:09.380
But before we save, let's also, uh, basically create instance of this camera set so you can go that

03:09.380 --> 03:16.180
chapter or that lecture in order to get, uh, this a singleton pattern and how you can use this serialized

03:16.180 --> 03:16.660
field.

03:16.660 --> 03:20.780
So I'm going to make a public static static.

03:20.820 --> 03:24.420
And we're going to make a camera check, camera check.

03:24.700 --> 03:26.580
And we're going to call it instance.

03:26.860 --> 03:28.780
So we're going to call it instance.

03:28.820 --> 03:31.180
And let's move over to this start function.

03:31.580 --> 03:35.220
And you can use find any object by type as well.

03:35.220 --> 03:40.060
If you just don't want to use this public static camera stick instance.

03:40.060 --> 03:42.660
But I'm going to use that to keep my clean code.

03:42.660 --> 03:43.460
So that's why.

03:43.500 --> 03:46.260
Or you can just ignore this process as well.

03:46.260 --> 03:47.700
It's totally up to you.

03:47.740 --> 03:53.540
Instead of saying serialize will, you can simply mark as a public, then animator and animator.

03:53.580 --> 04:00.020
so you can just do that as well if you, uh, just don't want to do this, so you can do that.

04:00.020 --> 04:08.260
So, uh, what I'm going to do now, I'm going to check if instance is equals, sorry is instance is

04:08.260 --> 04:09.900
equals equals to null.

04:09.940 --> 04:14.380
Then we're going to say sorry we will set instance equal to this.

04:14.380 --> 04:19.180
But before we do I'm going to make the first brackets and let's put it over here.

04:19.180 --> 04:23.340
So I'm going to say instance instance equal to this.

04:23.540 --> 04:29.860
If already instance there then I'm going to make else uh so make some curly brackets.

04:29.860 --> 04:35.460
Then I'm going to destroy the instance if already there is a instance.

04:35.620 --> 04:37.420
So let's close that up with semicolon.

04:37.420 --> 04:40.340
And let's press down Ctrl S to save our script.

04:40.340 --> 04:42.340
And let's move over to animator.

04:42.500 --> 04:43.140
Uh, sorry.

04:43.300 --> 04:44.900
Let's move over to unity.

04:44.900 --> 04:51.420
So underneath our camera script we can see, uh, camera shake script, we can see a animator and it

04:51.420 --> 04:53.030
says none animator.

04:53.030 --> 04:56.430
So the animator component is attached to this main camera.

04:56.430 --> 05:00.070
So I'm going to select our main camera and let's drag it into that slot.

05:00.070 --> 05:03.830
And now we can see we have main camera animator component.

05:03.830 --> 05:09.630
As you can see underneath our camera shake speed basically means we have this animator component by

05:09.670 --> 05:11.030
now of this main camera.

05:11.030 --> 05:13.950
And we are ready to trigger this shake parameter.

05:13.950 --> 05:17.030
So let's go to our script and let's make a function for that.

05:17.030 --> 05:19.230
So I'm going to make it somewhere in the bottom.

05:19.230 --> 05:21.270
And we're going to make that function public.

05:21.270 --> 05:21.550
Why.

05:21.590 --> 05:27.830
Because we're going to call this function through another class or another C script.

05:27.830 --> 05:29.190
So we're going to call that.

05:29.190 --> 05:31.870
So that's why we're going to mark that function as a public.

05:31.870 --> 05:33.550
So we're going to make a public.

05:33.550 --> 05:35.510
And for function we're going to type void.

05:35.510 --> 05:39.350
And I'm going to call this function to something like shake shake.

05:39.390 --> 05:42.630
And let's make first bracket and some curly brackets.

05:42.790 --> 05:49.270
And what we basically want to do, we have the reference of this animator component, as you can see

05:49.310 --> 05:54.910
in the inspector underneath our camera shake script over here, as you can see.

05:54.910 --> 05:56.390
So we have the reference.

05:56.390 --> 05:57.710
So we have the reference.

05:57.710 --> 06:04.310
So we can use this animator in order to trigger this shake parameter in animator tab we can see.

06:04.310 --> 06:05.550
So let's go to our script.

06:05.550 --> 06:07.470
So what we will do inside this function.

06:07.470 --> 06:10.310
Firstly we will move over to animator component.

06:10.310 --> 06:13.950
And then we're going to use this set trigger function.

06:13.950 --> 06:15.990
Why are we using this set trigger function.

06:15.990 --> 06:19.310
Because this parameter is a trigger parameter.

06:19.310 --> 06:24.230
So that's why we need to use this set trigger function in order to trigger that parameter.

06:24.230 --> 06:29.390
And inside this bracket in set trigger it's going to take the parameter name in quotation.

06:29.390 --> 06:31.910
So in quotation we're going to pass the parameter name.

06:31.910 --> 06:33.670
And the parameter name is sick.

06:33.670 --> 06:35.150
So we're going to simply pass sick.

06:35.150 --> 06:37.190
And let's close that up with semicolon.

06:37.190 --> 06:38.830
So what we simply doing.

06:38.870 --> 06:43.190
We just going over to animator and then triggering that parameter.

06:43.190 --> 06:49.840
Basically we just going over to this main camera animator component and by this animator component we

06:49.840 --> 06:52.960
just triggered in this triggering this shake parameter.

06:53.000 --> 06:55.360
As you can see in the animator tab.

06:55.360 --> 06:56.920
So basically that is the thing.

06:56.920 --> 07:01.120
So whenever we're going to call this check function and what check function is just going to do, it's

07:01.120 --> 07:02.680
going to move over to animator.

07:02.680 --> 07:05.440
And it's going to trigger the parameter called shake.

07:05.480 --> 07:06.520
As you can see.

07:06.520 --> 07:11.800
So we need to call the function when we should call this function once we take damage or shoot.

07:11.800 --> 07:14.960
But for now we're going to press down Ctrl S to save our script.

07:14.960 --> 07:16.320
And let's move to unity.

07:16.480 --> 07:19.920
Or simply you can just toggle it in the player script.

07:19.920 --> 07:25.720
But for for depth explanation I'm going to do uh, in unity editor.

07:25.720 --> 07:27.280
So just wait for to compile.

07:28.680 --> 07:31.240
And once it's done, we are ready to do that.

07:31.520 --> 07:38.680
So now so, uh, when we just want to call the check function once, this enemy game object takes damage

07:38.680 --> 07:41.560
as well as this player game object takes damage.

07:41.560 --> 07:43.280
So we're going to call the function there.

07:43.640 --> 07:49.360
And that function is just going to trigger this check parameter, which basically is checking our camera.

07:49.360 --> 07:51.600
So I'm going to open up my player script.

07:51.600 --> 07:54.200
So let's select the player game object in the hierarchy.

07:54.200 --> 07:57.200
And let's open up the player script by double clicking on it.

07:57.200 --> 08:02.040
So we're going to call the function when we took a taking damage from that enemy.

08:02.040 --> 08:07.800
So as you can see over here we're just taking the damage from the that enemy game object.

08:07.800 --> 08:11.480
So after taking damage we also want to shake our camera.

08:11.480 --> 08:13.400
So we're going to use this camera shake.

08:13.880 --> 08:19.440
Or you can simply use this find any object by type uh and then make this arrows.

08:19.520 --> 08:20.720
And into this arrows.

08:20.720 --> 08:25.160
You need to pass the script name that which script you just looking for.

08:25.160 --> 08:29.080
So in our case camera shake and then make first bracket.

08:29.080 --> 08:31.520
And you can simply call the function by dot.

08:31.560 --> 08:36.120
But instead of doing this I have created the singleton pattern.

08:36.120 --> 08:43.120
As you can see in this camera shake camera shake script which is public static camera shake instant

08:43.120 --> 08:44.200
as you can see.

08:44.200 --> 08:47.570
So I can simply pass the script name which is camera check.

08:47.570 --> 08:51.210
And then by this instance parameter I can call this check function.

08:51.210 --> 08:57.890
So that's why I created the singleton pattern instead of using find any object by type because that

08:57.890 --> 08:59.010
is fairly taxing.

08:59.010 --> 08:59.850
So that's why.

08:59.970 --> 09:01.530
Or you can just ignore this.

09:01.570 --> 09:09.330
Well if you just don't want to, don't want to basically call it a something like with singleton pattern,

09:09.330 --> 09:12.930
then you can just ignore this as start function as well as this one.

09:13.170 --> 09:14.730
So I hope you get the idea.

09:14.730 --> 09:16.770
So I'm gonna move over to my player script.

09:16.770 --> 09:18.810
So I have the singleton pattern.

09:18.810 --> 09:21.530
So I'm going to simply pass my camera check script name.

09:21.570 --> 09:23.770
And then I'm going to move over to Winston.

09:23.770 --> 09:26.370
And then I'm going to call the check function.

09:26.370 --> 09:30.530
And let's make first bracket and let's call close that output semicolon.

09:30.530 --> 09:34.210
So basically just going over to this camera check is a class.

09:34.210 --> 09:38.530
And then by this instance parameter I'm just calling the check function.

09:38.530 --> 09:44.500
And what check function is doing is just checking our camera or basically triggering that parameter,

09:44.500 --> 09:46.980
which is creating the shake animation.

09:46.980 --> 09:48.300
So let's go to player skip.

09:48.340 --> 09:53.140
Basically that we just simply calling the shake function, as you can see over here.

09:53.140 --> 09:57.100
But when we calling it once we're taking damage as you can see.

09:57.100 --> 09:59.980
So we're going to press down Ctrl S to save our skip.

09:59.980 --> 10:01.580
And let's move over to unity.

10:02.500 --> 10:04.060
So we're gonna able to see that.

10:07.540 --> 10:09.140
So just wait for to compile.

10:09.140 --> 10:14.900
So whenever we're gonna take damage from this enemy game object we will able to see the camera.

10:14.940 --> 10:16.380
Just gonna check right away.

10:16.380 --> 10:20.060
So let's click on this play button in the top to have a look on this.

10:20.060 --> 10:21.660
And let's check that out.

10:26.820 --> 10:33.300
Let's let's get closer to this enemy game object in order to take the damage from this enemy.

10:33.300 --> 10:34.980
So let's have a look on this.

10:35.460 --> 10:36.740
So just wait.

10:37.180 --> 10:41.660
As you can see, as soon as we taking damage from this enemy anime game object.

10:41.660 --> 10:46.460
We can see the camera is shaking and we also want to shake the camera.

10:46.460 --> 10:51.660
Once we once this anime to game object as well as the first anime taking damage.

10:51.660 --> 10:53.620
We also want to call the check function.

10:53.620 --> 10:55.460
Basically, it's going to check our.

10:55.900 --> 10:57.820
You can simply say our camera.

10:57.820 --> 11:02.060
So let's get out of play mode and let's select the anime to game object in the hierarchy.

11:02.060 --> 11:04.380
And let's open up the anime to script.

11:04.540 --> 11:10.540
So let's go to that function where we taking damage so we can see we taking damage over here.

11:10.540 --> 11:13.540
So after subtracting health I'm going to call the check function.

11:13.540 --> 11:15.060
So let's go to camera check.

11:15.180 --> 11:18.420
So camera check is a script that instant.

11:18.420 --> 11:21.460
And then let's call the check function and make first bracket.

11:21.460 --> 11:22.940
Close that up with semicolon.

11:22.940 --> 11:25.820
And I'm going to copy this line of code by Ctrl C.

11:25.900 --> 11:28.740
And I'm going to paste it in anime one as well.

11:28.740 --> 11:32.820
But before we do let's press Ctrl S to save our script.

11:32.820 --> 11:35.900
And let's go to first anime or anime one script.

11:35.900 --> 11:40.230
So this is a this script is attached to the first anime game object.

11:40.230 --> 11:42.390
So let's move over to Takedamage function.

11:42.390 --> 11:44.310
So over here we're taking damage.

11:44.310 --> 11:48.910
So I'm going to paste it by Ctrl V basically calling the check function as you can see.

11:48.910 --> 11:53.190
So once we take damage and I'm going to press down Ctrl S to save my script.

11:53.190 --> 11:59.390
But I also want to check my script once our enemy or the player game object totally get explored.

11:59.390 --> 12:04.830
So over here we can see we have the die function in inside our first enemy script.

12:04.830 --> 12:08.430
So I'm going to call the function over here as well by Ctrl V.

12:08.470 --> 12:11.270
So let's paste it basically calling the check function.

12:11.270 --> 12:15.950
And I'm going to do the same thing with my enemy too and as well as a player.

12:15.950 --> 12:17.590
So let's go to enemy two script.

12:17.590 --> 12:19.390
Let's move over to die function.

12:19.390 --> 12:24.430
And I'm going to paste the function over here as well as I'm going to move over to my player script

12:24.550 --> 12:26.310
and let's paste the dive.

12:26.390 --> 12:31.070
Uh, let's paste that line of code inside this dive function by Ctrl V.

12:31.230 --> 12:37.310
Now this is fine means whenever we just destroying our player enemy one and enemy two game GameObject.

12:37.310 --> 12:40.910
We are also calling the check function which is checking our camera.

12:40.910 --> 12:43.550
So I'm going to press down Ctrl S to save my script.

12:43.550 --> 12:45.470
And let's move to unity by now.

12:45.470 --> 12:51.870
So whenever this player and this enemy GameObject are just gonna explode or die, you will see.

12:51.870 --> 12:57.790
The camera will also say so just wait for it to compile and once it's done, we are ready to do that.

12:57.790 --> 13:01.150
So I'm going to click on this play button in the top to play our game.

13:01.390 --> 13:04.870
And let's take a look of what we have done so far.

13:05.150 --> 13:07.630
So just wait for to start our game.

13:07.630 --> 13:10.350
And once it's done, we are ready to do that.

13:10.350 --> 13:13.750
So I'm gonna, uh, shoot on this enemy game object.

13:14.430 --> 13:21.030
And as soon as enemy is taking damage, as you seen, uh, as you saw, the camera is just shaking right

13:21.030 --> 13:21.350
away.

13:21.350 --> 13:22.910
So I'm going to get out of play mode.

13:22.950 --> 13:24.710
I'm going to check it one more time.

13:24.710 --> 13:26.350
So let's click on this play button.

13:26.350 --> 13:32.950
But before I do, I'm just gonna give a little more health to this enemy GameObject for testing purposes.

13:32.950 --> 13:35.840
So I'm gonna select my enemy to GameObject in the hierarchy.

13:36.000 --> 13:38.800
And let's give Maxhealth something around five.

13:38.840 --> 13:41.040
And let's click on this play button in the top.

13:41.040 --> 13:43.960
So I just increased my enemy to health.

13:44.000 --> 13:45.440
For testing purposes.

13:45.960 --> 13:51.200
But it's totally up to you how much health you just want to give to your enemy GameObject.

13:51.200 --> 13:52.480
It's totally up to you!

13:52.480 --> 13:54.800
So I'm going to shoot on this enemy GameObject.

13:54.800 --> 14:01.960
As you can see, as soon as it's taking damage, the camera just shaking right away and we can see that.

14:01.960 --> 14:03.320
I hope you get the idea.

14:03.320 --> 14:06.640
So I'm gonna get out of play mode and let's take a look on this player.

14:06.640 --> 14:13.080
Basically, once this player GameObject takes damage or basically a die, the camera just gonna shake,

14:13.280 --> 14:14.240
uh, as well.

14:14.240 --> 14:19.960
So let's click on this play button and I'm not gonna attack on this enemy two game object right now

14:19.960 --> 14:24.680
because I want to check for now our with our player game object.

14:24.680 --> 14:26.200
So let's have a look on this.

14:27.200 --> 14:30.560
Firstly we need to get closer to our enemy GameObject.

14:30.560 --> 14:33.680
Then it's gonna attack on our player Layer GameObject.

14:33.680 --> 14:40.480
And as you can see indeed our player just taking damage and once it's die, the camera is also getting

14:40.520 --> 14:40.960
shaking.

14:40.960 --> 14:46.400
So whenever it takes damage player the camera is seeking as well as when it's dying.

14:46.440 --> 14:47.520
I hope you get the idea.

14:47.520 --> 14:51.480
So I'm gonna get out of play mode and that's it.

14:51.480 --> 14:55.240
And I'm going to make this camera shake game object as well a prefab.

14:55.240 --> 14:56.600
So we're going to have the copy.

14:56.600 --> 15:00.160
So I'm going to select my camera GameObject in the hierarchy.

15:00.320 --> 15:02.680
And let's drag it over to this prefab folder.

15:02.680 --> 15:07.480
Or you can simply drag it into this assets folder in project tab.

15:07.480 --> 15:16.040
But I'm going to drag it over my, uh, over on my prefabs folder because I have created a folder for

15:16.040 --> 15:22.040
our prefabs and I'm going to select my camera shake prefab, and I'm gonna drag it over to this, uh,

15:22.040 --> 15:29.160
object sub folder because, uh, I created a separate folder for those objects prefab.

15:29.200 --> 15:30.280
You can simply say.

15:30.560 --> 15:32.520
And now let's press down Ctrl s.
