WEBVTT

00:00.040 --> 00:06.040
Now we need to trigger the parameter, uh, of this, uh, of this parallel GameObject.

00:06.160 --> 00:09.800
So what we're going to do for that, we will open up our script.

00:09.840 --> 00:12.680
So let's select the parallel GameObject in the hierarchy.

00:12.800 --> 00:16.480
And let's open up the destructible script by double clicking on it.

00:16.480 --> 00:20.000
And let's make a function in order to make the transition.

00:20.160 --> 00:23.360
So I'm going to remove this start and update function.

00:23.360 --> 00:26.760
I don't need uh I don't need what we're going to do.

00:26.800 --> 00:29.840
We basically want to destroy.

00:30.400 --> 00:36.000
So what we will do uh for that we need a reference to this animator component.

00:36.160 --> 00:41.200
So if I select my barrel GameObject in the hierarchy, then move over to animator tab.

00:41.240 --> 00:44.520
As you can see, we need to trigger this destruct parameter.

00:44.520 --> 00:49.240
And it's going to play the barrel underscore destructible animation clip.

00:49.240 --> 00:52.440
So we need a reference of this animator component.

00:52.440 --> 00:57.800
As you can notice, this animator component is sitting on this barrel GameObject.

00:57.800 --> 00:59.880
So we need a reference to it.

00:59.880 --> 01:05.320
So let's open up our script by double clicking on it, and let's go to the top of our class and let's

01:05.320 --> 01:06.440
grab the reference.

01:06.440 --> 01:08.440
So we're going to make a serialized field.

01:09.440 --> 01:11.560
So let's make a serialized field.

01:11.600 --> 01:12.400
Just wait.

01:13.040 --> 01:14.440
It's a serialized field.

01:14.800 --> 01:16.520
And we're going to call this one.

01:16.520 --> 01:19.120
And let's mark this private.

01:19.160 --> 01:24.960
Even though we just marked as private and we just type serialize field basically means we still gonna

01:24.960 --> 01:31.640
be able to notice or still gonna able to access this parameter underneath our destructible script.

01:31.680 --> 01:33.160
And we have to name that.

01:33.600 --> 01:36.360
So we're looking for our animator component.

01:36.360 --> 01:38.360
So we're going to type this animator.

01:38.560 --> 01:41.720
And we can call this something like animator.

01:41.720 --> 01:44.040
So just a wait a little bit.

01:44.080 --> 01:45.080
It's lagging.

01:45.520 --> 01:51.560
Uh so animator and let's call it something like animator or we have to name the parameter.

01:51.560 --> 01:54.040
So let's call it animator something like that.

01:54.280 --> 01:56.240
And let's close that up with semicolon.

01:56.240 --> 01:59.440
And we're going to press down Ctrl control s to save our script.

01:59.440 --> 02:01.400
And now let's move over to unity.

02:01.640 --> 02:08.040
So underneath our an indestructible script, if we're just gonna pop up, which will be animator.

02:08.040 --> 02:11.880
So what we need to do there, we basically need to drag the reference.

02:11.880 --> 02:18.920
Basically we need to select our animator component and we need to drag it over to this destructible

02:19.040 --> 02:19.600
script.

02:20.200 --> 02:22.200
So we need to drag the reference.

02:22.200 --> 02:23.560
So just wait a moment.

02:23.560 --> 02:26.800
Once we're gonna have the animator component reference.

02:26.840 --> 02:27.080
Then.

02:27.080 --> 02:33.600
And then after that we can just uh, we can trigger this destruct parameter through our code.

02:33.720 --> 02:40.320
And as soon as we're going to do that, we will notice that this play, this battle game object, it's

02:40.320 --> 02:41.760
gonna destroy itself.

02:41.760 --> 02:44.480
Basically, it's gonna play that animation clip.

02:44.720 --> 02:46.880
Now, as you can see, it's done.

02:46.880 --> 02:52.920
So let's take our animator component and drag it over here to this animator slot.

02:52.920 --> 02:57.310
And by now we can notice that we have barrel Animator component.

02:57.310 --> 03:03.830
So let's open up our destructible script by double clicking on it, and let's make a function to trigger

03:03.830 --> 03:04.830
that parameter.

03:05.030 --> 03:10.310
And we're going to make this function public since we will call this function from another class.

03:10.310 --> 03:12.990
Or you can simply say another script.

03:12.990 --> 03:15.830
So that's why we're going to mark this function as public.

03:16.070 --> 03:18.350
And for function we're going to type void.

03:18.350 --> 03:20.350
And we have to name the function.

03:20.830 --> 03:30.270
So we can call this something like trigger a trigger a trigger animator or trigger animation something

03:30.270 --> 03:30.990
like that.

03:30.990 --> 03:34.950
We're going to call it let's make first bracket and some curly brackets.

03:35.110 --> 03:40.870
And what we want to do inside this function, we basically want to trigger that parameter which is this

03:40.870 --> 03:44.150
track as you seen in animator tab.

03:44.150 --> 03:47.230
So we're going to move over to our animator component first.

03:47.270 --> 03:54.550
Then we're going to we're going to use this dot set trigger function because that is a trigger parameter.

03:54.550 --> 03:55.910
And inside this bracket.

03:55.910 --> 04:01.630
In quotation, we need to pass the parameter name, which is distract and make sure you spell it correct.

04:01.670 --> 04:03.070
Else it's not going to work.

04:03.110 --> 04:05.270
And let's close that up with semicolon.

04:05.390 --> 04:08.430
And we're going to press down Ctrl s to save our script.

04:08.470 --> 04:10.230
And now we need to call this function.

04:10.230 --> 04:17.030
But when we should once our player game object just going to attack or that circle that we created from

04:17.030 --> 04:22.030
this player game object collide with this paddle game object, at that moment we're going to call that

04:22.030 --> 04:23.950
function which is destructible.

04:24.950 --> 04:26.470
So just wait a moment.

04:26.670 --> 04:31.110
And once it's done, we can just go ahead and we can do that.

04:31.110 --> 04:35.830
So we need to open up our player script for in order to do that.

04:36.070 --> 04:39.030
So let's select our player GameObject in the hierarchy.

04:39.070 --> 04:45.910
Let's go over to Inspector and let's open up the player script by double clicking on it and double clicking

04:45.910 --> 04:46.470
on it.

04:46.470 --> 04:47.390
And let's go.

04:47.590 --> 04:56.190
Let's move over to attack function where we attacking or damaging our enemy over here.

04:56.190 --> 04:59.510
As you can see, we are damaging our enemy too.

04:59.510 --> 05:03.030
And as you can notice right over here.

05:03.030 --> 05:09.910
So before we destroy or basically call that function, which is trigger animation of this paddle game

05:09.910 --> 05:14.630
object, we need to check if we just attack on this paddle or not.

05:14.630 --> 05:19.910
So as a damage we also gonna choose our barrel.

05:20.190 --> 05:26.710
So before we do barrel, basically play that animation clip or we call that animation clip.

05:26.750 --> 05:27.790
We're going to check.

05:27.790 --> 05:34.390
So we're doing uh inside this call info basically means the circle really colliding with that enemy.

05:34.390 --> 05:38.750
Or you can simply say with that enemy one, enemy two and the barrel.

05:38.750 --> 05:42.030
So what we will do right over here, we just want to check.

05:42.030 --> 05:48.310
So let's make let's make first bracket and some curly brackets and what we want to check over here.

05:48.310 --> 05:52.590
We basically want to check if that game object is a barrel or not.

05:52.590 --> 05:54.590
So we're going to use this hit info.

05:54.990 --> 05:55.510
Sorry.

05:55.910 --> 06:01.870
We're going to use this call info dot game object dot tag.

06:02.030 --> 06:06.230
So call info dot game object dot tag basically means the game object.

06:06.710 --> 06:08.710
This circle collided with.

06:08.710 --> 06:17.990
So we also gonna assign as a vertex player we're gonna assign our A as well this game object barrel

06:18.030 --> 06:18.790
game object.

06:18.830 --> 06:25.390
But before we do let's move over to our script and we will check if the tag is equals equals to our

06:25.390 --> 06:25.910
barrel.

06:26.190 --> 06:33.430
So if that is the case barrel if that is the case uh, then uh, what we need to do, we need to call

06:33.430 --> 06:38.470
the barrel function from our, uh, destructible script.

06:38.470 --> 06:40.630
So what what we're going to do now.

06:40.910 --> 06:42.150
Sorry, not the tech.

06:42.150 --> 06:42.990
We're gonna check.

06:43.110 --> 06:45.710
Instead we're going to get the animator component.

06:45.710 --> 06:48.590
So we're going to type this date dot get component.

06:48.590 --> 06:53.740
And we will check if that game object has a destructible a script or not.

06:53.740 --> 06:57.300
So let's pass our destructible script and we will check.

06:57.300 --> 07:01.660
So let's make first bucket and we will check if it's not equal to null.

07:01.700 --> 07:05.060
Basically means the game object the circle collided with.

07:05.100 --> 07:13.700
If that game object, uh, if that game object has a has a script called barrel, uh sorry script called

07:13.740 --> 07:16.180
uh destructible.

07:16.180 --> 07:20.500
So if I select my barrel GameObject in the hierarchy and go over to Inspector.

07:20.540 --> 07:26.820
As you can notice, the destructible script is attached to this, uh, parallel game object and we are

07:26.820 --> 07:28.340
checking right over here.

07:28.340 --> 07:33.180
So call info dot GameObject basically means the GameObject the circle collided with.

07:33.180 --> 07:39.740
So if the circle collided with this barrel game object, then their call info dot GameObject basically

07:39.740 --> 07:41.580
means this barrel game object.

07:41.580 --> 07:43.020
And after that what we doing?

07:43.020 --> 07:49.860
We just getting the destructible script from that game object and we can see if we select our barrel

07:49.860 --> 07:52.820
GameObject in the hierarchy, then go over to Inspector.

07:52.820 --> 07:58.540
We can notice that Destructable script is attached to this barrel GameObject, and we're checking if

07:58.540 --> 08:00.940
that script is not equal to null.

08:00.980 --> 08:07.900
Basically means that the basically means this destructible script is attached to our player GameObject

08:07.940 --> 08:09.700
it and it's not empty.

08:09.860 --> 08:15.820
And indeed we can notice that the destructible script is attached to this barrel GameObject.

08:15.820 --> 08:17.140
As you can notice.

08:17.980 --> 08:22.020
As you can notice, so are not equal to none.

08:22.020 --> 08:23.900
And we basically checking there.

08:23.940 --> 08:26.900
And now what we need to do we need to call the function.

08:26.900 --> 08:28.660
So what we will do for this.

08:28.700 --> 08:31.220
Firstly we will go to that barrel game object.

08:31.220 --> 08:34.340
And then we're going to access the destructible script.

08:34.340 --> 08:42.500
And from there we basically gonna call that you can simply say are we gonna call that function.

08:42.500 --> 08:49.300
So let's go to call info dot GameObject basically means we going over to that barrel game object and

08:49.300 --> 08:50.580
we're gonna get the component.

08:50.580 --> 08:52.900
So we're going to use this dot get component.

08:52.900 --> 08:59.060
And the component we're looking for is a destructible script or destructible C-sharp class.

08:59.060 --> 09:01.500
So we're going to pass that which is destructible.

09:01.500 --> 09:04.340
And make sure to use this make this first bracket.

09:04.340 --> 09:10.660
And from there we're going to call the function which is a trigger animation as we created inside our

09:10.660 --> 09:11.980
destructible script.

09:11.980 --> 09:15.740
So let's call that so dot trigger animation.

09:15.740 --> 09:18.020
And now we're going to close that up with semicolon.

09:18.180 --> 09:25.340
Uh so firstly make this first bracket in order to call the function and then close that up with semicolon.

09:25.340 --> 09:28.900
And we're going to press down Ctrl S in order to save our script.

09:29.180 --> 09:31.300
And let me explain one more time.

09:31.300 --> 09:37.380
So firstly we're going over to this game object and we're checking if the destructible script is not

09:37.380 --> 09:38.300
equal to null.

09:38.340 --> 09:42.900
Basically means that destructible script is attached to this barrel game object.

09:42.900 --> 09:49.060
And indeed we can notice the destructible script is attached to or sitting on this paddle game object.

09:49.100 --> 09:50.340
Then what we're doing.

09:50.380 --> 09:53.100
Then we're going over to this destructible strip.

09:53.100 --> 09:58.740
If I double click on it, and then calling this function and this function, basically going over to

09:58.780 --> 10:05.460
animator and then triggering that destruct parameter, as you seen, as we saw earlier, that if we

10:05.900 --> 10:13.180
trigger this destruct parameter, it's going to play that animation clip which is the destructible animation

10:13.180 --> 10:14.740
as you saw earlier.

10:14.860 --> 10:20.940
And now we're gonna go ahead and let's click on this play button in the top in order to play our game.

10:20.940 --> 10:27.260
And we will notice that as soon as the circle just gonna trigger with sorry, just gonna collide with

10:27.260 --> 10:35.460
this barrel game object the barrel just gonna play the animation clip, which is basically a destructible

10:35.460 --> 10:36.100
animation.

10:36.100 --> 10:37.500
So let's get closer.

10:37.820 --> 10:42.620
And if I select my player GameObject in the hierarchy, you can notice the circle.

10:42.820 --> 10:44.580
And now let's do that.

10:45.020 --> 10:47.100
so we not getting.

10:47.100 --> 10:51.220
So basically what we have to do now we need to get out of play mode.

10:51.260 --> 10:56.620
We forgot one thing to do that uh we also need to assign the layer.

10:56.740 --> 11:01.300
So if I select my barrel GameObject in the hierarchy then go over to Inspector.

11:01.300 --> 11:06.220
As you can notice, I have assigned this barrel as a barrel layer.

11:06.220 --> 11:11.940
So if I select my player skip uh sorry player GameObject in the hierarchy, then move over to player

11:11.940 --> 11:13.340
Skip in Inspector.

11:13.500 --> 11:18.700
As you can see in the bottom attack, we just only have assigned enemy layer.

11:18.700 --> 11:21.260
So we also want to choose this barrel layer.

11:21.260 --> 11:22.820
So we're going to choose this barrel.

11:22.820 --> 11:24.140
So let's click on it.

11:24.620 --> 11:26.660
Uh let's click on that barrel.

11:26.660 --> 11:29.980
So make sure you choose your barrel as well as enemy.

11:30.100 --> 11:36.300
And now if we go ahead and then click on this play button and then click get closer to this barrel game

11:36.340 --> 11:36.860
object.

11:36.860 --> 11:39.180
And then place a attack animation.

11:39.180 --> 11:45.970
You will able to notice that this barrel is just going to play that animation clip, which is which

11:45.970 --> 11:48.730
is the destructible animation clip.

11:48.930 --> 11:50.490
So just wait a moment.

11:51.210 --> 11:57.650
And, uh, but before we doing, we basically checking now if I just, uh, play attack animation,

11:57.650 --> 11:58.650
as you can see.

11:58.690 --> 12:03.130
Indeed it's now played that animation clip, as you can see.

12:03.610 --> 12:05.490
So basically this is the cool thing.

12:05.490 --> 12:09.730
But, uh, what we want to do now, we also need to destroy this.

12:09.730 --> 12:13.530
As you can see, we can see the splitting parts.

12:13.530 --> 12:18.570
So we also need to destroy after some amount of time this barrel completely.

12:18.570 --> 12:25.090
But before we destroy that, what we want to do, we basically want to disable our box collider 2D of

12:25.090 --> 12:25.850
this barrel.

12:26.210 --> 12:32.210
Uh, so barrel as well as we will set the rigid body, uh, gravity scale to zero.

12:32.210 --> 12:35.170
So it's not gonna fall down, uh, for gravity.

12:35.170 --> 12:40.130
So let's get out of play mode, and we're gonna do it inside our barrel script or.

12:40.170 --> 12:46.050
Sorry, not parallel Scrape we're going to do inside our destructible script.

12:46.050 --> 12:49.530
So let's select our parallel GameObject in the hierarchy.

12:49.570 --> 12:54.970
Let's go over to Inspector, and let's open up our destructible script by double clicking on it.

12:55.410 --> 12:57.130
So firstly we need a reference.

12:57.130 --> 13:05.050
So if I move over to unity we can see we have the rigidbody 2D and the box collider 2D inside this barrel

13:05.490 --> 13:06.370
game object.

13:06.370 --> 13:08.810
So you get the reference of both of these.

13:08.810 --> 13:11.730
So let's open up our script by double clicking on it.

13:11.730 --> 13:13.690
And let's go to the top of our class.

13:13.690 --> 13:15.450
And we don't need to make this public.

13:15.450 --> 13:20.010
So so we're going to use start function in order to grab the reference.

13:20.010 --> 13:22.010
So we're gonna make it private.

13:22.010 --> 13:25.490
And the component we're looking for is a rigid body 2D.

13:25.490 --> 13:27.650
So let's type this rigidbody 2D.

13:27.770 --> 13:29.930
And we can call this rigidbody 2D.

13:29.970 --> 13:33.050
I'm going to call it RB short for Rigidbody 2D.

13:33.050 --> 13:35.970
And the second thing we need that box collider.

13:36.130 --> 13:40.410
So we're gonna grab we're gonna make another private and private field.

13:40.450 --> 13:43.690
And the component we're looking for is a box Collider 2D.

13:43.690 --> 13:50.530
And we can call this a box Collider, or we can simply call a B-C like that.

13:50.570 --> 13:52.250
I'm going to call Box Collider.

13:52.410 --> 13:55.410
And now let's include the start function.

13:55.410 --> 13:57.770
So let's include this start function.

13:57.770 --> 14:01.410
So we do know that start function get call in the start of the game.

14:01.410 --> 14:04.450
So in the start of the game we need to craft the reference.

14:04.450 --> 14:08.370
Firstly we will go to rb dot GameObject dot.

14:08.410 --> 14:08.890
Sorry.

14:09.370 --> 14:15.170
Uh we can simply use this dot GameObject dot get component.

14:15.170 --> 14:18.330
And the component we're looking for is Rigidbody 2D.

14:18.330 --> 14:23.130
So we're going to type this rigidbody 2D and then make this first bracket and then close that up with

14:23.130 --> 14:24.050
semicolon.

14:24.330 --> 14:27.490
Now we have the rigidbody 2D as you can notice.

14:27.490 --> 14:34.650
And now we're going to store that this rigidbody 2D into this RB rigidbody 2D parameter.

14:34.650 --> 14:37.530
As you can see we created up here.

14:37.530 --> 14:41.530
So store into that field or parameter.

14:41.530 --> 14:47.010
So let's set rb equal to this dot GameObject dot get component rigid body 2d.

14:47.130 --> 14:52.850
What we basically doing this basically is just referencing itself with basically going over to this

14:52.850 --> 14:56.890
rigid body 2D, or we're just getting this rigid body 2D component.

14:56.890 --> 15:01.170
And then we restoring this rigid body 2D component into this RB.

15:01.250 --> 15:04.970
As you can notice right over here in the start of the function.

15:05.330 --> 15:08.650
And also we need to access the box collider 2D.

15:09.490 --> 15:11.410
Uh so let's do the same thing.

15:11.650 --> 15:16.290
So we're gonna use this start GameObject dot get component.

15:16.530 --> 15:19.770
And the component we're looking for is now Box Collider 2D.

15:19.770 --> 15:21.850
So we're going to type this box Collider 2D.

15:22.170 --> 15:28.170
And let's make this uh first bracket and then close that up with semicolon.

15:28.170 --> 15:30.450
And we have the box Collider 2D now.

15:30.450 --> 15:35.770
So let's store this box Collider 2D into this box Collider 2D variable.

15:35.810 --> 15:37.850
And let's set equal to this.

15:38.210 --> 15:45.050
So now we have the reference, uh, for uh, basically we have this box Collider 2D as well as this

15:45.050 --> 15:46.170
rigid body 2D.

15:46.170 --> 15:51.490
So if I select click on this rigid body 2D as you can see gravity scale three.

15:51.490 --> 15:53.050
So we're going to set it to zero.

15:53.050 --> 15:56.970
But before we set we just want to disable this box Collider 2D.

15:57.090 --> 16:02.690
So this barrel game object not gonna detect any collision if we just disable that.

16:02.690 --> 16:05.570
And after it we're gonna set the gravity scale to zero.

16:05.730 --> 16:09.570
And if we don't do that, it's gonna fall down due to our gravity.

16:09.570 --> 16:14.050
So that's why we're gonna set the rigid body 2D gravity scale to zero.

16:14.250 --> 16:19.370
So let's open up our script, and we're gonna do it inside this trigger animation function.

16:19.370 --> 16:23.490
So whenever we're playing that animation clip, then we're gonna do that.

16:23.490 --> 16:27.210
But, uh, so firstly we just want to set the gravity scale to zero.

16:27.210 --> 16:30.410
So let's go to RB dot gravity scale.

16:30.410 --> 16:32.850
And we're gonna set equal to zero F.

16:32.970 --> 16:36.720
Basically we're going over to this rigid body 2D.

16:36.720 --> 16:39.920
And we setting this gravity scale over here to zero.

16:39.960 --> 16:43.200
As you can notice in our script.

16:43.200 --> 16:46.720
And after that we also want to disable the box Collider 2D.

16:46.880 --> 16:49.160
So we will go to Box Collider 2D.

16:49.160 --> 16:52.160
And we're going to use dot enable dot enable.

16:52.160 --> 16:54.280
And we're going to set equal to false.

16:54.320 --> 16:58.520
False basically means that you just disabling that box Collider 2D.

16:58.680 --> 17:05.760
And if you set equal to true basically box collider dot enable equal to true means you just enabling

17:05.760 --> 17:07.840
that since we want to disable.

17:07.840 --> 17:12.680
So that's why we're using this box collider 2D dot enable equal to false.

17:12.680 --> 17:15.720
And now we're going to press down Ctrl S to save our script.

17:15.720 --> 17:17.600
And now let's move over to unity.

17:18.880 --> 17:26.440
And you will see as soon as uh as soon as this uh, barrel GameObject just gonna play that animation

17:26.440 --> 17:34.640
clip, which is uh, you can say, uh, you can say, um, sorry, really sorry.

17:35.000 --> 17:38.080
uh, animation clip, which is the distraction.

17:38.080 --> 17:44.320
You will able to notice this rigid body 2D gravity scale going to be zero as well as this just going

17:44.320 --> 17:45.000
to disable.

17:45.000 --> 17:49.000
So let's click on this play button in the top in order to play our game.

17:49.160 --> 17:51.160
And let's take a look on this.

17:51.520 --> 17:53.400
So just wait a moment.

17:53.400 --> 17:58.720
And once we're gonna attack on this paddle game object you will able to notice that.

18:01.080 --> 18:02.240
Just wait.

18:02.280 --> 18:06.880
And if we get closer to this parallel and then attack on it, as you can see.

18:06.920 --> 18:07.520
Indeed.

18:07.680 --> 18:11.840
Uh, indeed, if we select our barrel, uh, we.

18:12.040 --> 18:13.880
And then move over to Inspector.

18:13.880 --> 18:19.040
As you can notice, this box Collider 2D component get unchecked basically disable.

18:19.040 --> 18:24.480
And if we move over to our rigidbody 2D, we can see the gravity scale is to zero.

18:24.520 --> 18:25.880
It just sets to zero.

18:26.160 --> 18:27.560
So I'm going to get out of play mode.

18:27.560 --> 18:33.400
So after some amount of time we also need to destroy this barrel game object.

18:33.440 --> 18:34.920
We need to destroy that.

18:34.920 --> 18:38.760
But after how much amount of time we need to destroy that.

18:38.760 --> 18:43.640
So for to check that out, make sure you select your game object in the hierarchy.

18:43.760 --> 18:49.560
Then move over to your animation tab and then click over here and choose the barrel destructible and

18:49.560 --> 18:50.560
check the time.

18:50.560 --> 18:58.600
So as you can notice that, uh, something like uh .4.4 amount sorry, point eight.

18:58.640 --> 19:01.440
It just uh, destroying itself completely.

19:01.600 --> 19:01.960
Sorry.

19:02.000 --> 19:02.800
Not completely.

19:02.800 --> 19:08.960
Basically the playing the animation clip, which is I guess this right over here is one second.

19:09.280 --> 19:12.320
Uh, and this means point eight second.

19:12.320 --> 19:17.000
So after point eight second, we also need to destroy this barrel game object.

19:17.160 --> 19:23.000
And in order to destroy that, what we're gonna do, we're going to open up our script by double clicking

19:23.120 --> 19:25.000
sorry, clicking on it.

19:25.280 --> 19:27.960
And we're going to use this destroy function.

19:28.440 --> 19:35.120
Uh, so we just going over to this trigger animation function and we need to use this function in order

19:35.120 --> 19:37.160
to destroy and this function.

19:37.360 --> 19:41.360
As a first argument, it's going to take the game object that we want to destroy.

19:41.480 --> 19:47.040
So we want to destroy the game object itself or destructible game object.

19:47.040 --> 19:52.480
So as a first argument we're gonna pass this game object means referencing itself.

19:52.480 --> 19:55.800
And second thing comma, you can specify the time.

19:55.800 --> 20:00.760
So after 0.8 second as you seen it's completing the whole animation clip.

20:01.080 --> 20:09.240
So you can just put the time but for different animation like port or something like other, I don't

20:09.240 --> 20:15.680
want to destroy a specific time.

20:15.680 --> 20:20.800
So what I'm gonna do, I'm going to create a variable because we're going to have the pod game object

20:20.800 --> 20:24.160
as well, which will be a destructible object.

20:24.160 --> 20:29.080
And we do know that there are the animation is going to be a little bit different.

20:29.360 --> 20:32.310
Uh, it's it can be something like one second.

20:32.310 --> 20:38.910
So that's why for this we will go to top of our class and we can specify the time when we need to destroy

20:38.910 --> 20:39.270
that.

20:39.270 --> 20:44.150
So let's make a serialized file private and we can call.

20:44.390 --> 20:45.670
This will be float.

20:45.670 --> 20:47.510
And we can call destroy time.

20:47.510 --> 20:51.150
So let's call it destroy destroy.

20:51.190 --> 20:51.710
Sorry.

20:51.750 --> 20:55.590
This destroy time.

20:55.990 --> 20:56.910
Destroy time.

20:56.910 --> 21:01.750
And by default I'm gonna set equal to something like, uh, one f or once again.

21:02.030 --> 21:07.190
And as a second argument right over here, I'm gonna put my destroy time.

21:07.190 --> 21:12.070
So let's put destroy time, and let's close the semicolon and story time.

21:12.070 --> 21:18.430
We have chosen one basically means after one second, the barrel or game object is gonna destroy itself.

21:18.550 --> 21:21.430
But we do know that we just made it a serialized field.

21:21.430 --> 21:25.310
So we can just adjust, uh, in the inspector right away.

21:25.630 --> 21:28.390
So I'm gonna press down control s to save my script.

21:28.390 --> 21:30.350
And now let's move over to unity.

21:30.830 --> 21:35.870
And for this parallel game object, I'm going to choose the destroy time, which will be 0.8.

21:36.030 --> 21:39.070
And for the port game object it's going to be different.

21:39.070 --> 21:40.710
So just let me show you.

21:42.030 --> 21:49.550
So now if we go, as you can see, destroy time underneath our destructible script we can see is one

21:49.990 --> 21:51.350
for this parallel game object.

21:51.350 --> 21:58.030
We're going to choose point eight, since we know that this parallel game object playing the whole animation

21:58.030 --> 22:02.270
clip of destroy after something like 0.8 seconds.

22:02.270 --> 22:06.270
So that's why as a destroy time, I'm going to put point eight.

22:06.630 --> 22:11.350
So after this amount of time, this parallel game object is going to destroy itself.

22:11.350 --> 22:15.310
So let's click on this play button in the top in order to play our game.

22:15.310 --> 22:18.110
And you will note you gonna notice that.

22:18.630 --> 22:27.830
And we have to do one more thing and it's going to be fine because, uh, we have done a mistake already.

22:27.870 --> 22:29.230
So we're going to talk about that.

22:29.230 --> 22:30.990
But before we do, let's have a look.

22:31.230 --> 22:38.390
So if I now get closer to this barrel and if we click basically attack on it, we can see indeed that

22:38.390 --> 22:41.230
just get destroyed after 0.8 second.

22:41.270 --> 22:47.910
But the problem is that we also gonna have part game object as well as some other destructible objects.

22:47.910 --> 22:49.550
So I'm gonna get out of play mode.

22:49.590 --> 22:56.110
Instead of assigning this barrel as a barrel layer, we're gonna assign it with destructible layer because

22:56.150 --> 23:01.190
we're gonna have multiple, uh, you can simply say multiple destructible game objects.

23:01.190 --> 23:02.030
So that's why.

23:02.270 --> 23:07.470
So we will choose our barrel, then go over to Inspector and then click on this layer.

23:07.470 --> 23:10.550
As you can notice we just assign it as barrel.

23:10.550 --> 23:12.470
So we're going to click on this add layer.

23:12.710 --> 23:14.310
Instead of calling barrel.

23:14.310 --> 23:18.830
We're going to call it something like destructible because we're going to have multiple.

23:18.830 --> 23:25.230
So that's why we're going to have the port and all of those things so destructible.

23:25.750 --> 23:28.590
Sorry if I mis spelling that.

23:28.630 --> 23:29.830
Distract.

23:30.670 --> 23:32.150
Okay, so this is fine.

23:32.390 --> 23:34.550
And now we're going to choose our parallel.

23:34.550 --> 23:36.310
And we're going to assign with the layer.

23:36.310 --> 23:40.590
So go over to Inspector and assign with destructible.

23:40.590 --> 23:46.190
And now as you can notice we just assign it that and we're going to click on this overrides and then

23:46.190 --> 23:47.630
click on this apply all.

23:47.630 --> 23:49.950
So the changes you made it's going to be safe.

23:49.990 --> 23:54.110
And let's do the same thing with our board game object.

23:54.350 --> 23:58.710
So I'm gonna select my parallel GameObject in the hierarchy.

23:59.230 --> 24:03.310
And I'm gonna drag a little bit far away from my player game object.

24:03.310 --> 24:06.470
So let's choose our parallel GameObject in the hierarchy.

24:06.630 --> 24:09.670
And let's select this mob tool in the scene view.

24:10.590 --> 24:13.230
And I'm going to move it somewhere around here.

24:13.510 --> 24:15.630
So let's create with the port now.

24:15.790 --> 24:20.430
So let's move over to our project app assets and then sprites folder.

24:20.630 --> 24:22.270
And I'm gonna move.

24:22.790 --> 24:25.510
We have the sprite sheet right over here.

24:25.510 --> 24:28.910
So let's click on this arrow in order to see the individual.

24:28.910 --> 24:30.990
And let's find out the part one.

24:30.990 --> 24:33.950
And we also have the chest as you can notice.

24:34.310 --> 24:36.350
So we're going to talk about it later.

24:36.350 --> 24:41.190
So let's uh find out our part first I really apologize.

24:43.830 --> 24:47.830
To we have the parts I guess not this one.

24:49.710 --> 24:52.070
Uh, so this one right over here.

24:52.070 --> 24:58.670
So let's select that sprite individual sprite and drag it over to the scene view or into this hierarchy.

24:58.990 --> 25:01.190
As you can see, we have the part.

25:01.430 --> 25:05.990
And now what we're going to do, uh, we can make it a little bit bigger.

25:05.990 --> 25:08.870
So we can just go ahead and choose the sprite sheet.

25:09.030 --> 25:12.830
And then we can just make a less our pixel per unit.

25:13.070 --> 25:17.630
But for this part game object, I just wanted to in the X scale.

25:17.790 --> 25:19.030
So what I'm going to do.

25:19.030 --> 25:22.910
But before we do let's name this game object to something like part.

25:23.070 --> 25:27.580
So let's go over to Inspector and let's call it something like pot.

25:28.780 --> 25:32.660
And we're gonna add some components to this pot game object.

25:32.700 --> 25:36.260
First thing we're going to add a rigid body to the for gravity.

25:36.260 --> 25:38.380
So let's click on this add component.

25:38.940 --> 25:41.980
And let's add a rigid body 2D.

25:42.020 --> 25:44.740
Let's type that and it's going to pop up.

25:44.740 --> 25:46.420
And we're going to add that.

25:46.420 --> 25:48.460
So just weight rigid body 2D.

25:48.620 --> 25:51.780
And I'm gonna make the gravity scale to something like three.

25:51.980 --> 25:57.580
And the mass I'm going to choose something around five and collision detection I'm going to choose continuous

25:57.580 --> 26:00.260
interpolate to interpolate to making smooth.

26:00.260 --> 26:03.340
And we're going to freeze the rotation about z axis.

26:03.580 --> 26:07.980
And let's add up our box collider 2D component for collision detection.

26:07.980 --> 26:15.340
Or we can just add any collider 2D that we like since we're gonna add box Collider 2D.

26:15.340 --> 26:21.220
And if we move over to script, we can see we have the Box Collider 2D reference in the start of the

26:21.220 --> 26:21.700
game.

26:21.700 --> 26:26.540
So that's why, uh, we're gonna attach to every single game.

26:26.580 --> 26:28.900
Object of destructible game object.

26:29.220 --> 26:32.740
The same collider, which will be our box Collider 2D.

26:32.820 --> 26:39.820
Since we're gonna attach the same destructible script to, uh, to all, uh, destructible, uh, game

26:39.860 --> 26:40.540
objects.

26:40.660 --> 26:46.300
Uh, so let's click on this add component and we're gonna add Box Collider 2D by typing that.

26:46.460 --> 26:52.420
And now we need to edit the collider as the size of our pod game object or Pod sprite.

26:52.420 --> 26:58.220
So let's click on this Edit Collider inside this box Collider 2D or 2D component.

26:58.220 --> 26:59.260
And the Inspector.

26:59.420 --> 27:03.740
And let's edit the collider as the size of our pod game object.

27:03.740 --> 27:05.100
Something like this much.

27:06.220 --> 27:06.780
Sorry.

27:08.060 --> 27:09.380
So let's select the pod.

27:09.420 --> 27:17.060
Let's click on this edit edit and let's edit this like that.

27:17.260 --> 27:19.540
And let's move it a little bit down.

27:20.060 --> 27:22.900
And as you can see, it's fine.

27:23.100 --> 27:29.060
And we're gonna assign this pod game object as a our destructible layer.

27:29.100 --> 27:29.380
Why?

27:29.420 --> 27:32.940
Because this will be our destructible layer.

27:32.980 --> 27:34.540
Basically this pod game object.

27:34.540 --> 27:37.460
So that's why for that let's go over to Inspector.

27:37.500 --> 27:40.620
Then we can assign layer as a destructible.

27:40.780 --> 27:44.740
And we're gonna assign as a destructible tag.

27:44.780 --> 27:47.820
As you can notice, we just already assign it.

27:48.020 --> 27:50.700
And now we need to make the animation of it.

27:50.700 --> 27:52.420
So let's make the animation.

27:52.420 --> 27:55.940
So the first animation gonna be the pot idle.

27:55.940 --> 27:58.300
So let's select the pot GameObject in the hierarchy.

27:58.300 --> 28:02.620
Let's go to animation tab and then click on this create button.

28:03.540 --> 28:06.860
And let's go over to assets in the top left.

28:06.860 --> 28:11.260
Then animation other animation destructible animation.

28:11.260 --> 28:15.140
And we're gonna call this animation clip to something like Pot idle.

28:15.340 --> 28:17.900
So let's call it pot underscore idle.

28:18.820 --> 28:20.660
And let's click on the save button.

28:21.180 --> 28:28.300
And what we're going to do in this, we basically just want to play this same sprite animation from

28:28.340 --> 28:30.100
and from start to end.

28:30.140 --> 28:34.260
To do that, make sure you select your pod GameObject in the hierarchy.

28:34.420 --> 28:40.540
Go over to animation tab and then click on this red button in order to capture the animation or basically

28:40.540 --> 28:42.300
to record your animation.

28:42.300 --> 28:44.220
Then click on this add property.

28:44.700 --> 28:49.140
Then we will go to Sprite Renderer and let's scroll down to the bottom.

28:49.140 --> 28:52.860
And we're going to click on this plus icon in this sprite.

28:52.860 --> 28:54.260
And the bottom we can see.

28:54.500 --> 28:58.300
And now as you can see we have the same sprite animation.

28:58.300 --> 28:59.260
And we are done.

28:59.260 --> 29:03.060
So let's click on this red button to capture the animation.

29:03.060 --> 29:08.100
And now we need to create the destructible animation clip of this pod GameObject.

29:08.140 --> 29:14.540
To do that, we will head over to our project tab and then assets and then sprites folder.

29:14.540 --> 29:17.340
And we can see we have it over here.

29:17.340 --> 29:21.100
So I'm going to select from this start to end right over here.

29:21.100 --> 29:22.860
So all of these sprite.

29:23.220 --> 29:25.140
Sprites are destructible.

29:25.140 --> 29:27.660
So we're gonna hold down shift on our keyboard.

29:27.660 --> 29:32.940
And we're going to select that and make sure you drag it top of your pot GameObject in the hierarchy

29:33.100 --> 29:35.700
in order to make the animation right away.

29:35.700 --> 29:42.700
So let's go to assets animation and other animation destructible animation.

29:42.700 --> 29:46.380
And we're going to call this something like Pod destructible.

29:46.380 --> 29:53.500
So let's call it Pod distract destructible like that.

29:53.500 --> 29:55.500
And let's click on the save button.

29:55.660 --> 29:59.060
And now if we I'm going to select my pod GameObject in the hierarchy.

29:59.100 --> 30:03.460
Let's drag it in the top of our hierarchy so we can see all the time.

30:03.460 --> 30:10.420
And if I select my pod and then move over to my animation tab, and then choose this pod destructible,

30:10.420 --> 30:12.060
and then click on this play button.

30:12.060 --> 30:15.860
As you can see, it's playing the animation which is destructible.

30:15.860 --> 30:18.690
Table are destructible as you can notice.

30:18.890 --> 30:20.770
So this basically looks fine.

30:20.770 --> 30:25.730
And let's suppose you just want to make your board game object a little bit bigger.

30:25.890 --> 30:28.090
I'm going to choose the ideal sprite first.

30:28.610 --> 30:30.050
Let's suppose you want.

30:30.490 --> 30:33.570
So make sure you select your board object in the hierarchy.

30:33.610 --> 30:38.770
Then go over to Inspector Transform and Transform and go over to scale.

30:38.770 --> 30:42.970
In the Y you can put something like 1.5 sorry.

30:43.010 --> 30:48.690
In the X you can put 1.5, and in the Y we can do the same thing 1.5.

30:48.810 --> 30:52.410
In order to make it a little bit bigger as you can notice.

30:52.650 --> 30:55.610
So this seems pretty much cool as you can notice.

30:55.930 --> 31:00.250
And now what we're going to do, uh, we basically need to make the transition.

31:00.250 --> 31:07.290
But before we do I don't want any, uh, the destructible animation clip to be loop of this board game

31:07.330 --> 31:07.930
object.

31:07.930 --> 31:14.530
So for that we're going to move over to our project tab assets, then animation folder then other animation

31:14.650 --> 31:19.490
folder, destructible animation folder, and we can see the part over here.

31:19.490 --> 31:22.690
We have the part idle as well as the part destructible.

31:22.690 --> 31:26.330
So I'm going to select both of these animation clip by holding down shift.

31:26.330 --> 31:28.090
And then go over to Inspector.

31:28.130 --> 31:29.730
And let's uncheck the loop time.

31:29.730 --> 31:31.690
So it's not going to loop at all.

31:31.930 --> 31:37.050
And now what we are going to do we can just go ahead and we can just add the script.

31:37.050 --> 31:42.650
But before we do let's make the transition from our part idle to part Distractable.

31:42.650 --> 31:45.450
So let's select our part GameObject in the hierarchy.

31:45.610 --> 31:50.370
Let's go over to animator tab and let's right click on this idle part idle.

31:50.370 --> 31:53.090
And let's make transition to part destructible.

31:53.290 --> 31:55.050
And let's select this transition.

31:55.050 --> 31:56.570
Let's go over to Inspector.

31:56.610 --> 32:03.370
We're going to uncheck the has exit time as well as we gonna set the transition duration to zero.

32:03.530 --> 32:09.050
And if we scroll down to the bottom we need to choose a condition since we're going to attach the same

32:09.050 --> 32:09.610
script.

32:09.610 --> 32:18.810
So we need to give the same trigger parameter name as we have done inside our game object, as you saw

32:18.810 --> 32:19.370
earlier.

32:19.490 --> 32:21.330
So we're going to do the same thing.

32:21.490 --> 32:24.570
So let's move over to animator tab then parameters.

32:24.570 --> 32:26.330
Let's click on this plus icon.

32:26.370 --> 32:27.930
And we're going to choose the trigger.

32:27.930 --> 32:32.650
And make sure you just name it as you have done it inside your game object.

32:32.650 --> 32:38.050
Since we just gonna attach the same script to this pot game object as well.

32:38.050 --> 32:40.490
So the parameter is distract.

32:40.730 --> 32:43.330
Let's call it distract and distract.

32:43.330 --> 32:45.170
And we're going to choose a transition.

32:45.170 --> 32:49.210
Let's go over to Inspector and let's click on this plus icon in the condition.

32:49.210 --> 32:50.970
In the bottom we can notice.

32:50.970 --> 32:52.690
So now we have done it.

32:52.890 --> 32:56.530
And what we're going to do now we're going to select our pot game object.

32:56.530 --> 33:01.490
And let's attach the script which is our uh destructible script.

33:01.490 --> 33:05.970
So we will for that we can just move over to our project app assets.

33:06.010 --> 33:12.690
And then we can head over to Script Folder basically in which folder we just created that As is script.

33:12.690 --> 33:18.970
So as you can so notice right over I have so I am I'm gonna select that script and then drag it over

33:18.970 --> 33:23.210
to this add component section in the inspector or what else you can do.

33:23.250 --> 33:30.210
You can simply click on this add component and you can just uh, find the component or the script by

33:30.530 --> 33:32.210
typing the name of the script.

33:32.210 --> 33:34.530
And the name of this script is destruct.

33:34.530 --> 33:35.730
So we can type that.

33:35.730 --> 33:38.890
As you can see, as soon as we type it just pop up.

33:38.890 --> 33:45.010
I'm not gonna click on it in order to attach it twice since I already attached, as you can see.

33:45.290 --> 33:50.890
And inside this script we can see we need the animator component and we don't have it.

33:50.890 --> 33:56.570
So we're gonna take our animator and let's drag it over to our animator field or slot.

33:56.610 --> 34:03.850
Now we can see we have the reference of it, and now we need to destroy this bot game object some period

34:03.850 --> 34:04.530
of time.

34:04.530 --> 34:07.530
So as a destroy time we're gonna choose a different number.

34:07.530 --> 34:13.640
So that's why we just made this destroy time as public for different destructible game objects.

34:13.640 --> 34:18.280
Just gonna have different time lapse of destruction animation clips.

34:18.280 --> 34:19.040
So that's why.

34:19.160 --> 34:20.640
So we're going to select our port.

34:20.680 --> 34:24.560
Let's go over to animation tab and we're going to choose destructible.

34:24.560 --> 34:27.120
So let's click over here for destructible.

34:27.120 --> 34:29.680
So we can notice this one as well.

34:29.680 --> 34:34.200
It's just playing the whole animation clip after 0.8 second.

34:34.760 --> 34:39.600
So we're going to put as a destroy time something like .8.8.

34:39.840 --> 34:41.240
And now it's done.

34:41.240 --> 34:44.120
And make sure you select this part game object as well.

34:44.160 --> 34:45.960
Make this one as a prefab.

34:45.960 --> 34:47.480
So you will have the copy.

34:47.680 --> 34:50.520
And we're going to paste it in our level level.

34:50.520 --> 34:51.520
So that's why.

34:51.560 --> 34:54.520
So we will select our part GameObject in the hierarchy.

34:54.720 --> 34:59.760
And let's drag it over to this prefabs folder in order to turn it into a prefab.

34:59.800 --> 35:01.440
Now we turn it into a prefab.

35:01.440 --> 35:02.920
So make sure you just do that.

35:03.240 --> 35:09.280
And if we just go ahead and then click on this play button, you will notice that as soon as we're gonna

35:09.320 --> 35:11.240
attack on this board game object.

35:12.320 --> 35:17.720
Uh, basically that, uh, that animation just gonna play, which is poured destructible.

35:17.960 --> 35:24.880
And once the animation completely plays, then after 0.8 seconds, this board game object just gonna

35:24.880 --> 35:28.120
destroy itself after 0.8 seconds.

35:28.120 --> 35:29.640
So let's check that out.

35:29.680 --> 35:33.640
Firstly, I'm gonna get closer to it and let's, uh, let's attack on it.

35:33.640 --> 35:38.680
As you can see, indeed, after 0.8 seconds, it just destroyed itself.

35:38.800 --> 35:47.040
And if we just destroy this barrel, we can notice after 0.8 seconds it just, uh, doing that and I'm

35:47.040 --> 35:48.400
gonna get out of play mode.

35:48.400 --> 35:51.080
So I hope you get the idea that how you can do it.

35:51.080 --> 35:58.480
And it's, uh, pretty much cool to see that we have some destructible game objects in our game, and

35:58.520 --> 36:01.560
it's really make our game too much cool.

36:01.560 --> 36:03.160
So basically, that is the thing.

36:03.320 --> 36:08.560
And make sure you press down Ctrl S on your keyboard in order to save your project.
