WEBVTT

00:00.040 --> 00:02.720
Let's create some destructible objects.

00:02.720 --> 00:07.960
To do so, I'm going to move over to my project tab assets, and then I will head over to my sprites

00:07.960 --> 00:08.480
folder.

00:08.880 --> 00:11.560
And as you can see I have the sprite sheet.

00:11.560 --> 00:12.680
So let's select that.

00:12.720 --> 00:16.760
Then go over to Inspector and then click on this Open Sprite editor.

00:17.040 --> 00:19.280
So as soon as we click we can see.

00:19.320 --> 00:21.840
Now we're going to slice it individually.

00:21.840 --> 00:27.240
To do that sprite mode we're going to choose multiple in inspector and pixel per unit.

00:27.240 --> 00:29.120
Let's make it something 16.

00:29.320 --> 00:32.200
And to get rid of blurry we're going to choose point No filter.

00:32.200 --> 00:35.120
And let's click on this apply button in the bottom right.

00:35.440 --> 00:40.760
And instead of slicing automatic we're going to slice a grid by cell count.

00:40.760 --> 00:43.960
So let's click on this slice in our Sprite Editor tab.

00:43.960 --> 00:47.040
And let's select Automatic Tool grid by cell count.

00:47.080 --> 00:49.720
Let's count how many columns and rows we have.

00:50.080 --> 00:51.240
So let's go

00:51.600 --> 00:58.000
123456789

00:58.280 --> 00:59.680
ten 1112.

00:59.680 --> 01:06.760
So 12 rows I'm going gonna put 12 column, 12 rows, and let's count the columns one, two, three,

01:06.800 --> 01:08.760
four, five, six, seven.

01:08.760 --> 01:11.160
So seven columns and 12 rows.

01:11.280 --> 01:15.680
And after doing that let's click on this slice and then click on this apply button.

01:15.680 --> 01:18.160
And I'm going to select my game view once again.

01:18.160 --> 01:20.040
And let's go over to that spreadsheet.

01:20.040 --> 01:23.440
And let's click on this arrow in order to see the individual.

01:23.640 --> 01:27.520
So we have the port uh port right over here.

01:27.520 --> 01:28.600
So let's select that.

01:28.600 --> 01:32.520
I'm going to select the first uh frame or the first sprite.

01:32.560 --> 01:35.960
Let's just drag it over to the scene view or into this hierarchy.

01:36.200 --> 01:40.960
As you can see we uh we are able to see our, uh, barrel.

01:41.000 --> 01:41.560
Sorry.

01:41.760 --> 01:44.480
This this this not is a port.

01:44.640 --> 01:46.440
Basically, this is our barrel.

01:46.680 --> 01:48.680
So we're going to name it to something like barrel.

01:48.680 --> 01:52.480
But before we do we just want to make it a little bit bigger.

01:52.480 --> 01:56.000
So we need to shrink down our pixel per unit number.

01:56.000 --> 01:58.880
So we're going to select our sprite sheet one more time.

01:59.160 --> 02:00.640
And let's go over to Inspector.

02:00.640 --> 02:07.000
And let's make this pixel per unit something around 12 and let's click on this apply button in the bottom.

02:07.120 --> 02:08.880
Now it seems pretty much fine.

02:09.200 --> 02:11.520
And let's rename it to something like pattern.

02:11.520 --> 02:15.800
So let's go over to Inspector and let's rename it to barrel.

02:16.520 --> 02:17.560
Uh barrel.

02:17.600 --> 02:20.520
Sorry, it should be barrel I don't know spelling.

02:20.920 --> 02:23.160
Let's call it barrel, something like that.

02:23.160 --> 02:26.440
And if I miss spelling I really apologize for it.

02:26.720 --> 02:31.040
And we're going to assign this barrel with, uh, destructible layer.

02:31.040 --> 02:35.200
But before we do, let's add some components to this barrel game object.

02:35.200 --> 02:36.640
So let's go over to Inspector.

02:36.640 --> 02:38.680
Let's click on this add component.

02:38.680 --> 02:42.080
First thing we're going to add a rigid body 2D for gravity.

02:42.080 --> 02:44.800
So let's find rigid body 2D by typing.

02:45.520 --> 02:45.640
Uh.

02:45.640 --> 02:47.600
So type right over here rigid body.

02:47.600 --> 02:49.200
And let's attach that.

02:49.200 --> 02:52.320
And I'm going to increase my uh gravity scale.

02:52.320 --> 02:57.040
So let's go over to this rigid body 2D component uh then gravity scale.

02:57.040 --> 02:59.920
And let's choose uh three something like that.

02:59.960 --> 03:01.080
And collision detection.

03:01.080 --> 03:06.000
We're going to choose continuous and interpolate to interpolate to making smooth.

03:06.120 --> 03:08.360
And we can freeze the z rotation.

03:08.360 --> 03:09.800
And now that's pretty fine.

03:10.160 --> 03:15.960
And we're gonna add one more components for collision detection which will be a box collider 2D.

03:16.120 --> 03:23.160
Or you can add any collider 2D that you like, but I'm gonna add a box Collider 2D in order to fit this

03:23.160 --> 03:24.000
perfectly.

03:24.240 --> 03:29.280
So let's click on this add component and let's add up our box Collider 2D.

03:29.560 --> 03:32.760
And let's click on this Edit Collider right over here.

03:32.760 --> 03:36.960
And let's edit the collider as the size of our barrel sprite.

03:37.080 --> 03:41.160
Something like that I guess this seems pretty much fine.

03:41.880 --> 03:47.280
And let's drag it this one up here, and let's drag this down here.

03:47.280 --> 03:50.360
And now as you can see now we just made it.

03:50.360 --> 03:57.080
And now let's assign this sorry, this barrel game object as a barrel tag or as a barrel layer.

03:57.080 --> 04:00.760
So to do that we're going to select our parallel GameObject in the hierarchy.

04:01.120 --> 04:02.720
And then go over to Inspector.

04:02.790 --> 04:04.710
We can see in the top right layer.

04:04.710 --> 04:05.870
So let's click there.

04:05.910 --> 04:10.310
Let's click on Add Layer and let's add a layer for our panel.

04:10.790 --> 04:12.710
And let's select our barrel.

04:12.750 --> 04:14.750
Let's go over to Inspector one more time.

04:14.750 --> 04:19.390
And let's assign the layer with our parallel as we recently created.

04:19.630 --> 04:27.350
And we can also take this game object as a destroy game object or destruction a destructible object,

04:27.350 --> 04:28.470
something like that.

04:28.510 --> 04:29.830
We can do it.

04:29.830 --> 04:30.910
So let's do it.

04:30.910 --> 04:32.310
So let's go over to Inspector.

04:32.310 --> 04:33.870
Let's click on this attack.

04:33.870 --> 04:37.430
Let's click on Add Tag and let's click on this plus icon.

04:37.430 --> 04:48.470
And we're going to create a destruct distract destructible destructible destructible something like

04:48.470 --> 04:51.670
that I guess the spelling is correct or not.

04:51.710 --> 04:52.510
We need to check.

04:52.510 --> 04:54.470
So I'm going to click on that save button.

04:54.790 --> 04:57.430
And I'm going to head over to my script folder.

04:57.710 --> 05:00.230
I have a script which is destroy.

05:00.270 --> 05:04.310
Basically I just want to check the name which is distract.

05:04.310 --> 05:05.790
I'm going to just right click on it.

05:05.790 --> 05:09.310
Let's click on this copy and I'm going to select my barrel.

05:09.630 --> 05:12.230
Let's go over to let's click on this add tag.

05:12.310 --> 05:14.510
And then I'm gonna remove this tag.

05:14.510 --> 05:16.390
Let's click on this plus icon.

05:16.390 --> 05:19.150
And I'm going to press this which is destructible.

05:19.150 --> 05:20.510
Let's click on the save.

05:20.670 --> 05:24.030
And now we're going to select our barrel GameObject in the hierarchy.

05:24.070 --> 05:25.550
Then go over to Inspector.

05:25.550 --> 05:28.230
And we're gonna assign with our destructible.

05:28.270 --> 05:31.750
Now we assign it this barrel GameObject as a destructible.

05:32.030 --> 05:35.270
So uh, so I hope you get the idea.

05:35.390 --> 05:36.950
We what we doing.

05:36.990 --> 05:39.750
And now we're gonna make two animation of this barrel.

05:39.790 --> 05:45.630
Firstly, it's just gonna be static and the second it will be destroyed it's going to play the destructible

05:45.630 --> 05:46.750
animation clip.

05:47.030 --> 05:48.430
So we're gonna do that.

05:48.430 --> 05:51.070
So for it we need the animation tab.

05:51.390 --> 05:54.550
So let's go select our barrel game object first.

05:54.550 --> 05:57.910
And I'm going to drag my animation tab somewhere over here.

05:58.110 --> 06:02.350
Sorry I'm going to press down control Z to undo.

06:02.910 --> 06:04.470
And we can see.

06:04.470 --> 06:09.350
So let's create the animation and make sure you select your panel GameObject in the hierarchy.

06:09.510 --> 06:11.190
Then go over to animation tab.

06:11.190 --> 06:16.790
Click on this create button and let's move over to our animation folder.

06:16.910 --> 06:25.030
Let's go over to other animation folder and let's create a sub folder for our Destructible objects animation.

06:25.030 --> 06:28.590
So let's right click then New New folder.

06:28.590 --> 06:35.430
And let's call this folder to something like destructible destructible destruct.

06:35.430 --> 06:40.790
Sorry destruct dis destructible.

06:43.310 --> 06:51.870
Destructible I don't know I really miss destruct table destructible.

06:52.630 --> 06:54.670
It should be P sorry.

06:54.710 --> 07:01.750
Destructible underscore animation animation and hit enter in order to create that.

07:01.750 --> 07:05.670
And let's open up this sub folder as well by double clicking on it.

07:05.670 --> 07:09.710
And now, uh, we have to name the animation what we want to name it.

07:09.710 --> 07:11.390
So this will be barrel idle.

07:11.390 --> 07:14.710
We can simply say and it's going to be static, something like that.

07:14.710 --> 07:17.670
It's not going to play any other animation clip.

07:17.670 --> 07:21.710
So when I say something like barrel underscore idle.

07:21.830 --> 07:27.590
So let's call that and let's click on the save button and it's going to create the animation.

07:27.590 --> 07:29.350
Now we're going to select our barrel.

07:29.390 --> 07:34.110
Go to animation tab and then click on this red button to capture the animation.

07:34.110 --> 07:37.190
And let's click on this add property at property.

07:37.190 --> 07:39.190
Then go over to Sprite Renderer.

07:39.470 --> 07:42.030
Then scroll down to the bottom says sprite.

07:42.030 --> 07:45.990
So just click on this plus icon you can see in the right side.

07:45.990 --> 07:51.350
And now if I just select my barrel game object in the hierarchy, then go over to animation tab and

07:51.350 --> 07:52.670
then click on this play button.

07:52.670 --> 07:56.990
As you can see, the animation is playing and the barrel is static.

07:57.110 --> 08:02.310
And now we need to create the destructible animation clip of this barrel.

08:02.310 --> 08:06.390
But before we do, let's click on this red button to capture the animation.

08:06.390 --> 08:10.110
And I'm going to drag my animation tab over here once again.

08:10.430 --> 08:14.550
And we need to create the destructible animation clip of this barrel.

08:14.590 --> 08:20.550
To do that we need to move over to our project tab, then assets folder and then sprites folder.

08:20.710 --> 08:23.430
And we can see we have the animation over here.

08:23.430 --> 08:30.950
As you can notice from this, uh, and if I just hold down my hold down Ctrl and scroll my scroll,

08:30.950 --> 08:36.590
my mouse wheel, as you can see, we can see our animations, individual sprite.

08:36.590 --> 08:39.990
So from over here I'm going to select to the end.

08:40.190 --> 08:46.150
So this sprite by holding down shift are playing the animation clip of destructible.

08:46.150 --> 08:52.470
So we're going to select that and then drag it over to this barrel GameObject in the top of this parallel

08:52.470 --> 08:53.950
GameObject in the hierarchy.

08:54.310 --> 08:57.030
Then we're going to move over to Assets Animation.

08:57.190 --> 08:58.230
Other animation.

08:58.230 --> 09:02.470
We created this destructible animation folder as you can notice.

09:02.470 --> 09:05.070
So let's open that up sub folder as well.

09:05.070 --> 09:07.030
And we have to name the animation.

09:07.030 --> 09:10.310
So this will be barrel underscore destructible.

09:10.550 --> 09:16.630
So let's call it destruct uh destruct destructible.

09:17.070 --> 09:19.550
Sorry destructible something like that.

09:19.550 --> 09:21.670
And let's click on the save button.

09:21.670 --> 09:27.870
And if I select my barrel GameObject by now and then move over to animation tab and then select click

09:27.870 --> 09:28.510
over here.

09:28.510 --> 09:31.270
And then choose this barrel underscore destructible.

09:31.270 --> 09:32.910
And then click on this play button.

09:32.910 --> 09:38.710
As you can notice, it's playing the destructible animation clip over again and again.

09:38.710 --> 09:40.110
So basically that is fine.

09:40.350 --> 09:45.030
And I don't want this animation clip to be loop which is destructible.

09:45.030 --> 09:49.950
So that's why we're going to move over to our project tab assets and then animation folder.

09:49.990 --> 09:55.470
Basically we need to move over to that folder in which folder we just created the animation clip of

09:55.470 --> 09:57.550
this barrel game object.

09:57.550 --> 10:00.630
So we have done it inside this animation folder.

10:00.670 --> 10:04.670
And then other animation folder, then destructible animation folder.

10:04.670 --> 10:07.350
And we can notice both of these animation clip.

10:07.350 --> 10:10.030
We have the destructible and the idle.

10:10.030 --> 10:11.830
So I'm going to choose my destructible.

10:11.830 --> 10:15.270
Let's go over to Inspector and I'm going to uncheck the loop type.

10:15.790 --> 10:18.710
And I'm going to leave the barrel idle as it is.

10:18.710 --> 10:22.070
Or we can simply uncheck this well as well.

10:22.070 --> 10:23.070
We can do that.

10:23.070 --> 10:26.390
And we're going to create a script for this barrel game object.

10:26.430 --> 10:31.710
To do that make sure you just go over to your project app assets and head over to Script Folder.

10:31.910 --> 10:37.110
Or you can simply right click on this assets or right click on your script folder.

10:37.110 --> 10:39.270
Then go to top in the create.

10:39.270 --> 10:42.190
And then you click on this Monobehaviour script.

10:42.190 --> 10:44.310
Or you can just go over to scripting.

10:44.350 --> 10:49.350
Then click on this Monobehaviour script and you can name that script to something like barrel.

10:49.390 --> 10:54.110
I already created a barrel script and I have it inside my script folder.

10:54.110 --> 10:57.190
As you can notice right over here, I have.

10:57.190 --> 11:01.910
So I'm going to choose my barrel game object in the hierarchy, and let's select that script and drag

11:01.910 --> 11:04.910
it over to this Add component section in Inspector.

11:04.950 --> 11:11.630
Now we we can see, we just attach our Distractible script to this Distractible game object.

11:11.710 --> 11:12.630
Game object.

11:12.630 --> 11:15.190
And now we're going to make the animation transition.

11:15.190 --> 11:18.750
So if I just go ahead and then click on this play button in the top.

11:18.750 --> 11:21.710
Sorry if I just click play button in the top.

11:21.710 --> 11:24.110
You will see as soon as our game.

11:24.110 --> 11:26.310
Just gonna start this battle game object.

11:26.310 --> 11:29.990
Just gonna play the barrel underscore idle animation clip.

11:29.990 --> 11:36.670
So we also need to play the destructible animation clip of this barrel once our player game object just

11:36.670 --> 11:41.310
gonna attack on this barrel or it's just gonna do that thing.

11:41.990 --> 11:49.470
So just wait a little moment and we can see barrel is is just playing that animation clip.

11:49.470 --> 11:54.510
So if I choose my barrel GameObject in the hierarchy, then move over to animator tab.

11:54.510 --> 12:01.270
As you can notice right over here inside our animator we can see barrel underscore idle animation clip

12:01.270 --> 12:03.510
is playing over again and again.

12:03.510 --> 12:08.260
So we also need to make transition from this barrel idle to barrel destructible.

12:08.260 --> 12:13.900
But when we shoot once this player game object just gonna attack on this parallel game object.

12:13.900 --> 12:15.420
So let's get out of play mode.

12:15.420 --> 12:17.820
So we basically need to make transition.

12:17.820 --> 12:20.260
So make sure you select your game object.

12:20.260 --> 12:26.340
Then go over to animator tab and make transition from this barrel idle to barrel destructible.

12:26.340 --> 12:28.700
So we're going to right click on this barrel idle.

12:28.700 --> 12:31.500
And let's make transition to barrel destructible.

12:31.500 --> 12:33.380
And let's select this transition.

12:33.380 --> 12:35.020
Let's go over to Inspector.

12:35.020 --> 12:37.220
And we're gonna uncheck the has exit time.

12:37.220 --> 12:43.540
Because as soon as our player GameObject just gonna attack on top of this barrel game object, it should

12:43.540 --> 12:47.420
play the barrel destructible animation clip right away.

12:47.420 --> 12:51.940
So that's why I just has untick the has exit time and transition duration.

12:51.940 --> 12:53.140
I'm gonna choose zero.

12:53.300 --> 12:59.100
And now if we scroll down we need to choose a condition right over here as you can notice.

12:59.100 --> 13:01.220
So we're going to choose a trigger condition.

13:01.220 --> 13:08.020
So we will create a parameter in order to move over to this animation clip which is barrel destructible

13:08.060 --> 13:08.580
to do so.

13:08.620 --> 13:13.740
Let's move over to our animator tab, then parameters, and then click on this plus icon.

13:13.740 --> 13:15.380
And we're going to choose a trigger.

13:15.380 --> 13:18.340
And let's call this trigger to something like destructible.

13:18.660 --> 13:22.100
Or let's call it let's call it destruct.

13:22.260 --> 13:24.380
Something like that destruct.

13:24.420 --> 13:25.500
Let's call that.

13:25.660 --> 13:30.260
And we're going to select this transition from this barrel idle to barrel destructible.

13:30.300 --> 13:31.220
Let's select that.

13:31.220 --> 13:35.140
Go over to Inspector and let's scroll down to the bottom condition.

13:35.140 --> 13:37.740
As you can notice it says list is empty.

13:37.900 --> 13:39.700
So let's click on this plus icon.

13:39.700 --> 13:42.380
And we're going to choose this destruct parameter.

13:42.380 --> 13:46.380
And now if we go ahead and then click on this play button in the top.

13:46.380 --> 13:50.020
You will see as soon as our game just gonna start this barrel.

13:50.060 --> 13:56.140
Just gonna play the barrel underscore idle animation clip over again and again once.

13:56.260 --> 13:59.660
But once we gonna trigger this destruct parameter.

13:59.660 --> 14:04.700
You will able to notice it's gonna play the barrel destructible animation clip.

14:04.740 --> 14:09.140
As you can notice, it's playing the barrel parallel underscore idle animation clip.

14:09.140 --> 14:15.620
And if I just manually trigger this destruct parameter, as you can notice, it just placed the barrel

14:15.660 --> 14:18.140
underscore destructible animation clip.

14:18.140 --> 14:20.820
And we can see and we can notice that.

14:20.820 --> 14:26.260
So we need to destroy this after playing the whole animation clip of barrel destructible.

14:26.260 --> 14:27.900
So I'm going to get out of play mode.

14:27.900 --> 14:31.060
And make sure you make this barrel game object a prefab.

14:31.060 --> 14:32.660
So you will have the copy.

14:32.660 --> 14:36.020
And you can just put it anywhere you need in the level.

14:36.020 --> 14:37.620
So you can just put that.

14:37.620 --> 14:40.860
So let's select our barrel game object in the hierarchy.

14:41.140 --> 14:42.780
Let's go over to project tab.

14:43.020 --> 14:46.820
Then we're going to head over to assets folder then prefabs folder.

14:46.820 --> 14:49.660
And let's select our barrel GameObject in the hierarchy.

14:49.660 --> 14:53.220
And let's drag it over to the inside this prefabs folder.

14:53.260 --> 14:55.580
Now we just turn it into a prefab.

14:55.580 --> 14:57.140
So I hope you get the idea.

14:57.340 --> 15:00.140
And we need to do the transition through our code.

15:00.180 --> 15:04.540
Once this player GameObject just attack on this barrel game object.

15:04.540 --> 15:08.900
So I hope you get the idea that how you can make destructible objects.
