Let's create some destructible objects.
To do so, I'm going to move over to my project tab assets, and then I will head over to my sprites
folder.
And as you can see I have the sprite sheet.
So let's select that.
Then go over to Inspector and then click on this Open Sprite editor.
So as soon as we click we can see.
Now we're going to slice it individually.
To do that sprite mode we're going to choose multiple in inspector and pixel per unit.
Let's make it something 16.
And to get rid of blurry we're going to choose point No filter.
And let's click on this apply button in the bottom right.
And instead of slicing automatic we're going to slice a grid by cell count.
So let's click on this slice in our Sprite Editor tab.
And let's select Automatic Tool grid by cell count.
Let's count how many columns and rows we have.
So let's go
123456789
ten 1112.
So 12 rows I'm going gonna put 12 column, 12 rows, and let's count the columns one, two, three,
four, five, six, seven.
So seven columns and 12 rows.
And after doing that let's click on this slice and then click on this apply button.
And I'm going to select my game view once again.
And let's go over to that spreadsheet.
And let's click on this arrow in order to see the individual.
So we have the port uh port right over here.
So let's select that.
I'm going to select the first uh frame or the first sprite.
Let's just drag it over to the scene view or into this hierarchy.
As you can see we uh we are able to see our, uh, barrel.
Sorry.
This this this not is a port.
Basically, this is our barrel.
So we're going to name it to something like barrel.
But before we do we just want to make it a little bit bigger.
So we need to shrink down our pixel per unit number.
So we're going to select our sprite sheet one more time.
And let's go over to Inspector.
And let's make this pixel per unit something around 12 and let's click on this apply button in the bottom.
Now it seems pretty much fine.
And let's rename it to something like pattern.
So let's go over to Inspector and let's rename it to barrel.
Uh barrel.
Sorry, it should be barrel I don't know spelling.
Let's call it barrel, something like that.
And if I miss spelling I really apologize for it.
And we're going to assign this barrel with, uh, destructible layer.
But before we do, let's add some components to this barrel game object.
So let's go over to Inspector.
Let's click on this add component.
First thing we're going to add a rigid body 2D for gravity.
So let's find rigid body 2D by typing.
Uh.
So type right over here rigid body.
And let's attach that.
And I'm going to increase my uh gravity scale.
So let's go over to this rigid body 2D component uh then gravity scale.
And let's choose uh three something like that.
And collision detection.
We're going to choose continuous and interpolate to interpolate to making smooth.
And we can freeze the z rotation.
And now that's pretty fine.
And we're gonna add one more components for collision detection which will be a box collider 2D.
Or you can add any collider 2D that you like, but I'm gonna add a box Collider 2D in order to fit this
perfectly.
So let's click on this add component and let's add up our box Collider 2D.
And let's click on this Edit Collider right over here.
And let's edit the collider as the size of our barrel sprite.
Something like that I guess this seems pretty much fine.
And let's drag it this one up here, and let's drag this down here.
And now as you can see now we just made it.
And now let's assign this sorry, this barrel game object as a barrel tag or as a barrel layer.
So to do that we're going to select our parallel GameObject in the hierarchy.
And then go over to Inspector.
We can see in the top right layer.
So let's click there.
Let's click on Add Layer and let's add a layer for our panel.
And let's select our barrel.
Let's go over to Inspector one more time.
And let's assign the layer with our parallel as we recently created.
And we can also take this game object as a destroy game object or destruction a destructible object,
something like that.
We can do it.
So let's do it.
So let's go over to Inspector.
Let's click on this attack.
Let's click on Add Tag and let's click on this plus icon.
And we're going to create a destruct distract destructible destructible destructible something like
that I guess the spelling is correct or not.
We need to check.
So I'm going to click on that save button.
And I'm going to head over to my script folder.
I have a script which is destroy.
Basically I just want to check the name which is distract.
I'm going to just right click on it.
Let's click on this copy and I'm going to select my barrel.
Let's go over to let's click on this add tag.
And then I'm gonna remove this tag.
Let's click on this plus icon.
And I'm going to press this which is destructible.
Let's click on the save.
And now we're going to select our barrel GameObject in the hierarchy.
Then go over to Inspector.
And we're gonna assign with our destructible.
Now we assign it this barrel GameObject as a destructible.
So uh, so I hope you get the idea.
We what we doing.
And now we're gonna make two animation of this barrel.
Firstly, it's just gonna be static and the second it will be destroyed it's going to play the destructible
animation clip.
So we're gonna do that.
So for it we need the animation tab.
So let's go select our barrel game object first.
And I'm going to drag my animation tab somewhere over here.
Sorry I'm going to press down control Z to undo.
And we can see.
So let's create the animation and make sure you select your panel GameObject in the hierarchy.
Then go over to animation tab.
Click on this create button and let's move over to our animation folder.
Let's go over to other animation folder and let's create a sub folder for our Destructible objects animation.
So let's right click then New New folder.
And let's call this folder to something like destructible destructible destruct.
Sorry destruct dis destructible.
Destructible I don't know I really miss destruct table destructible.
It should be P sorry.
Destructible underscore animation animation and hit enter in order to create that.
And let's open up this sub folder as well by double clicking on it.
And now, uh, we have to name the animation what we want to name it.
So this will be barrel idle.
We can simply say and it's going to be static, something like that.
It's not going to play any other animation clip.
So when I say something like barrel underscore idle.
So let's call that and let's click on the save button and it's going to create the animation.
Now we're going to select our barrel.
Go to animation tab and then click on this red button to capture the animation.
And let's click on this add property at property.
Then go over to Sprite Renderer.
Then scroll down to the bottom says sprite.
So just click on this plus icon you can see in the right side.
And now if I just select my barrel game object in the hierarchy, then go over to animation tab and
then click on this play button.
As you can see, the animation is playing and the barrel is static.
And now we need to create the destructible animation clip of this barrel.
But before we do, let's click on this red button to capture the animation.
And I'm going to drag my animation tab over here once again.
And we need to create the destructible animation clip of this barrel.
To do that we need to move over to our project tab, then assets folder and then sprites folder.
And we can see we have the animation over here.
As you can notice from this, uh, and if I just hold down my hold down Ctrl and scroll my scroll,
my mouse wheel, as you can see, we can see our animations, individual sprite.
So from over here I'm going to select to the end.
So this sprite by holding down shift are playing the animation clip of destructible.
So we're going to select that and then drag it over to this barrel GameObject in the top of this parallel
GameObject in the hierarchy.
Then we're going to move over to Assets Animation.
Other animation.
We created this destructible animation folder as you can notice.
So let's open that up sub folder as well.
And we have to name the animation.
So this will be barrel underscore destructible.
So let's call it destruct uh destruct destructible.
Sorry destructible something like that.
And let's click on the save button.
And if I select my barrel GameObject by now and then move over to animation tab and then select click
over here.
And then choose this barrel underscore destructible.
And then click on this play button.
As you can notice, it's playing the destructible animation clip over again and again.
So basically that is fine.
And I don't want this animation clip to be loop which is destructible.
So that's why we're going to move over to our project tab assets and then animation folder.
Basically we need to move over to that folder in which folder we just created the animation clip of
this barrel game object.
So we have done it inside this animation folder.
And then other animation folder, then destructible animation folder.
And we can notice both of these animation clip.
We have the destructible and the idle.
So I'm going to choose my destructible.
Let's go over to Inspector and I'm going to uncheck the loop type.
And I'm going to leave the barrel idle as it is.
Or we can simply uncheck this well as well.
We can do that.
And we're going to create a script for this barrel game object.
To do that make sure you just go over to your project app assets and head over to Script Folder.
Or you can simply right click on this assets or right click on your script folder.
Then go to top in the create.
And then you click on this Monobehaviour script.
Or you can just go over to scripting.
Then click on this Monobehaviour script and you can name that script to something like barrel.
I already created a barrel script and I have it inside my script folder.
As you can notice right over here, I have.
So I'm going to choose my barrel game object in the hierarchy, and let's select that script and drag
it over to this Add component section in Inspector.
Now we we can see, we just attach our Distractible script to this Distractible game object.
Game object.
And now we're going to make the animation transition.
So if I just go ahead and then click on this play button in the top.
Sorry if I just click play button in the top.
You will see as soon as our game.
Just gonna start this battle game object.
Just gonna play the barrel underscore idle animation clip.
So we also need to play the destructible animation clip of this barrel once our player game object just
gonna attack on this barrel or it's just gonna do that thing.
So just wait a little moment and we can see barrel is is just playing that animation clip.
So if I choose my barrel GameObject in the hierarchy, then move over to animator tab.
As you can notice right over here inside our animator we can see barrel underscore idle animation clip
is playing over again and again.
So we also need to make transition from this barrel idle to barrel destructible.
But when we shoot once this player game object just gonna attack on this parallel game object.
So let's get out of play mode.
So we basically need to make transition.
So make sure you select your game object.
Then go over to animator tab and make transition from this barrel idle to barrel destructible.
So we're going to right click on this barrel idle.
And let's make transition to barrel destructible.
And let's select this transition.
Let's go over to Inspector.
And we're gonna uncheck the has exit time.
Because as soon as our player GameObject just gonna attack on top of this barrel game object, it should
play the barrel destructible animation clip right away.
So that's why I just has untick the has exit time and transition duration.
I'm gonna choose zero.
And now if we scroll down we need to choose a condition right over here as you can notice.
So we're going to choose a trigger condition.
So we will create a parameter in order to move over to this animation clip which is barrel destructible
to do so.
Let's move over to our animator tab, then parameters, and then click on this plus icon.
And we're going to choose a trigger.
And let's call this trigger to something like destructible.
Or let's call it let's call it destruct.
Something like that destruct.
Let's call that.
And we're going to select this transition from this barrel idle to barrel destructible.
Let's select that.
Go over to Inspector and let's scroll down to the bottom condition.
As you can notice it says list is empty.
So let's click on this plus icon.
And we're going to choose this destruct parameter.
And now if we go ahead and then click on this play button in the top.
You will see as soon as our game just gonna start this barrel.
Just gonna play the barrel underscore idle animation clip over again and again once.
But once we gonna trigger this destruct parameter.
You will able to notice it's gonna play the barrel destructible animation clip.
As you can notice, it's playing the barrel parallel underscore idle animation clip.
And if I just manually trigger this destruct parameter, as you can notice, it just placed the barrel
underscore destructible animation clip.
And we can see and we can notice that.
So we need to destroy this after playing the whole animation clip of barrel destructible.
So I'm going to get out of play mode.
And make sure you make this barrel game object a prefab.
So you will have the copy.
And you can just put it anywhere you need in the level.
So you can just put that.
So let's select our barrel game object in the hierarchy.
Let's go over to project tab.
Then we're going to head over to assets folder then prefabs folder.
And let's select our barrel GameObject in the hierarchy.
And let's drag it over to the inside this prefabs folder.
Now we just turn it into a prefab.
So I hope you get the idea.
And we need to do the transition through our code.
Once this player GameObject just attack on this barrel game object.
So I hope you get the idea that how you can make destructible objects.