Now we need to trigger the parameter, uh, of this, uh, of this parallel GameObject.
So what we're going to do for that, we will open up our script.
So let's select the parallel GameObject in the hierarchy.
And let's open up the destructible script by double clicking on it.
And let's make a function in order to make the transition.
So I'm going to remove this start and update function.
I don't need uh I don't need what we're going to do.
We basically want to destroy.
So what we will do uh for that we need a reference to this animator component.
So if I select my barrel GameObject in the hierarchy, then move over to animator tab.
As you can see, we need to trigger this destruct parameter.
And it's going to play the barrel underscore destructible animation clip.
So we need a reference of this animator component.
As you can notice, this animator component is sitting on this barrel GameObject.
So we need a reference to it.
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
grab the reference.
So we're going to make a serialized field.
So let's make a serialized field.
Just wait.
It's a serialized field.
And we're going to call this one.
And let's mark this private.
Even though we just marked as private and we just type serialize field basically means we still gonna
be able to notice or still gonna able to access this parameter underneath our destructible script.
And we have to name that.
So we're looking for our animator component.
So we're going to type this animator.
And we can call this something like animator.
So just a wait a little bit.
It's lagging.
Uh so animator and let's call it something like animator or we have to name the parameter.
So let's call it animator something like that.
And let's close that up with semicolon.
And we're going to press down Ctrl control s to save our script.
And now let's move over to unity.
So underneath our an indestructible script, if we're just gonna pop up, which will be animator.
So what we need to do there, we basically need to drag the reference.
Basically we need to select our animator component and we need to drag it over to this destructible
script.
So we need to drag the reference.
So just wait a moment.
Once we're gonna have the animator component reference.
Then.
And then after that we can just uh, we can trigger this destruct parameter through our code.
And as soon as we're going to do that, we will notice that this play, this battle game object, it's
gonna destroy itself.
Basically, it's gonna play that animation clip.
Now, as you can see, it's done.
So let's take our animator component and drag it over here to this animator slot.
And by now we can notice that we have barrel Animator component.
So let's open up our destructible script by double clicking on it, and let's make a function to trigger
that parameter.
And we're going to make this function public since we will call this function from another class.
Or you can simply say another script.
So that's why we're going to mark this function as public.
And for function we're going to type void.
And we have to name the function.
So we can call this something like trigger a trigger a trigger animator or trigger animation something
like that.
We're going to call it let's make first bracket and some curly brackets.
And what we want to do inside this function, we basically want to trigger that parameter which is this
track as you seen in animator tab.
So we're going to move over to our animator component first.
Then we're going to we're going to use this dot set trigger function because that is a trigger parameter.
And inside this bracket.
In quotation, we need to pass the parameter name, which is distract and make sure you spell it correct.
Else it's not going to work.
And let's close that up with semicolon.
And we're going to press down Ctrl s to save our script.
And now we need to call this function.
But when we should once our player game object just going to attack or that circle that we created from
this player game object collide with this paddle game object, at that moment we're going to call that
function which is destructible.
So just wait a moment.
And once it's done, we can just go ahead and we can do that.
So we need to open up our player script for in order to do that.
So let's select our player GameObject in the hierarchy.
Let's go over to Inspector and let's open up the player script by double clicking on it and double clicking
on it.
And let's go.
Let's move over to attack function where we attacking or damaging our enemy over here.
As you can see, we are damaging our enemy too.
And as you can notice right over here.
So before we destroy or basically call that function, which is trigger animation of this paddle game
object, we need to check if we just attack on this paddle or not.
So as a damage we also gonna choose our barrel.
So before we do barrel, basically play that animation clip or we call that animation clip.
We're going to check.
So we're doing uh inside this call info basically means the circle really colliding with that enemy.
Or you can simply say with that enemy one, enemy two and the barrel.
So what we will do right over here, we just want to check.
So let's make let's make first bracket and some curly brackets and what we want to check over here.
We basically want to check if that game object is a barrel or not.
So we're going to use this hit info.
Sorry.
We're going to use this call info dot game object dot tag.
So call info dot game object dot tag basically means the game object.
This circle collided with.
So we also gonna assign as a vertex player we're gonna assign our A as well this game object barrel
game object.
But before we do let's move over to our script and we will check if the tag is equals equals to our
barrel.
So if that is the case barrel if that is the case uh, then uh, what we need to do, we need to call
the barrel function from our, uh, destructible script.
So what what we're going to do now.
Sorry, not the tech.
We're gonna check.
Instead we're going to get the animator component.
So we're going to type this date dot get component.
And we will check if that game object has a destructible a script or not.
So let's pass our destructible script and we will check.
So let's make first bucket and we will check if it's not equal to null.
Basically means the game object the circle collided with.
If that game object, uh, if that game object has a has a script called barrel, uh sorry script called
uh destructible.
So if I select my barrel GameObject in the hierarchy and go over to Inspector.
As you can notice, the destructible script is attached to this, uh, parallel game object and we are
checking right over here.
So call info dot GameObject basically means the GameObject the circle collided with.
So if the circle collided with this barrel game object, then their call info dot GameObject basically
means this barrel game object.
And after that what we doing?
We just getting the destructible script from that game object and we can see if we select our barrel
GameObject in the hierarchy, then go over to Inspector.
We can notice that Destructable script is attached to this barrel GameObject, and we're checking if
that script is not equal to null.
Basically means that the basically means this destructible script is attached to our player GameObject
it and it's not empty.
And indeed we can notice that the destructible script is attached to this barrel GameObject.
As you can notice.
As you can notice, so are not equal to none.
And we basically checking there.
And now what we need to do we need to call the function.
So what we will do for this.
Firstly we will go to that barrel game object.
And then we're going to access the destructible script.
And from there we basically gonna call that you can simply say are we gonna call that function.
So let's go to call info dot GameObject basically means we going over to that barrel game object and
we're gonna get the component.
So we're going to use this dot get component.
And the component we're looking for is a destructible script or destructible C-sharp class.
So we're going to pass that which is destructible.
And make sure to use this make this first bracket.
And from there we're going to call the function which is a trigger animation as we created inside our
destructible script.
So let's call that so dot trigger animation.
And now we're going to close that up with semicolon.
Uh so firstly make this first bracket in order to call the function and then close that up with semicolon.
And we're going to press down Ctrl S in order to save our script.
And let me explain one more time.
So firstly we're going over to this game object and we're checking if the destructible script is not
equal to null.
Basically means that destructible script is attached to this barrel game object.
And indeed we can notice the destructible script is attached to or sitting on this paddle game object.
Then what we're doing.
Then we're going over to this destructible strip.
If I double click on it, and then calling this function and this function, basically going over to
animator and then triggering that destruct parameter, as you seen, as we saw earlier, that if we
trigger this destruct parameter, it's going to play that animation clip which is the destructible animation
as you saw earlier.
And now we're gonna go ahead and let's click on this play button in the top in order to play our game.
And we will notice that as soon as the circle just gonna trigger with sorry, just gonna collide with
this barrel game object the barrel just gonna play the animation clip, which is basically a destructible
animation.
So let's get closer.
And if I select my player GameObject in the hierarchy, you can notice the circle.
And now let's do that.
so we not getting.
So basically what we have to do now we need to get out of play mode.
We forgot one thing to do that uh we also need to assign the layer.
So if I select my barrel GameObject in the hierarchy then go over to Inspector.
As you can notice, I have assigned this barrel as a barrel layer.
So if I select my player skip uh sorry player GameObject in the hierarchy, then move over to player
Skip in Inspector.
As you can see in the bottom attack, we just only have assigned enemy layer.
So we also want to choose this barrel layer.
So we're going to choose this barrel.
So let's click on it.
Uh let's click on that barrel.
So make sure you choose your barrel as well as enemy.
And now if we go ahead and then click on this play button and then click get closer to this barrel game
object.
And then place a attack animation.
You will able to notice that this barrel is just going to play that animation clip, which is which
is the destructible animation clip.
So just wait a moment.
And, uh, but before we doing, we basically checking now if I just, uh, play attack animation,
as you can see.
Indeed it's now played that animation clip, as you can see.
So basically this is the cool thing.
But, uh, what we want to do now, we also need to destroy this.
As you can see, we can see the splitting parts.
So we also need to destroy after some amount of time this barrel completely.
But before we destroy that, what we want to do, we basically want to disable our box collider 2D of
this barrel.
Uh, so barrel as well as we will set the rigid body, uh, gravity scale to zero.
So it's not gonna fall down, uh, for gravity.
So let's get out of play mode, and we're gonna do it inside our barrel script or.
Sorry, not parallel Scrape we're going to do inside our destructible script.
So let's select our parallel GameObject in the hierarchy.
Let's go over to Inspector, and let's open up our destructible script by double clicking on it.
So firstly we need a reference.
So if I move over to unity we can see we have the rigidbody 2D and the box collider 2D inside this barrel
game object.
So you get the reference of both of these.
So let's open up our script by double clicking on it.
And let's go to the top of our class.
And we don't need to make this public.
So so we're going to use start function in order to grab the reference.
So we're gonna make it private.
And the component we're looking for is a rigid body 2D.
So let's type this rigidbody 2D.
And we can call this rigidbody 2D.
I'm going to call it RB short for Rigidbody 2D.
And the second thing we need that box collider.
So we're gonna grab we're gonna make another private and private field.
And the component we're looking for is a box Collider 2D.
And we can call this a box Collider, or we can simply call a B-C like that.
I'm going to call Box Collider.
And now let's include the start function.
So let's include this start function.
So we do know that start function get call in the start of the game.
So in the start of the game we need to craft the reference.
Firstly we will go to rb dot GameObject dot.
Sorry.
Uh we can simply use this dot GameObject dot get component.
And the component we're looking for is Rigidbody 2D.
So we're going to type this rigidbody 2D and then make this first bracket and then close that up with
semicolon.
Now we have the rigidbody 2D as you can notice.
And now we're going to store that this rigidbody 2D into this RB rigidbody 2D parameter.
As you can see we created up here.
So store into that field or parameter.
So let's set rb equal to this dot GameObject dot get component rigid body 2d.
What we basically doing this basically is just referencing itself with basically going over to this
rigid body 2D, or we're just getting this rigid body 2D component.
And then we restoring this rigid body 2D component into this RB.
As you can notice right over here in the start of the function.
And also we need to access the box collider 2D.
Uh so let's do the same thing.
So we're gonna use this start GameObject dot get component.
And the component we're looking for is now Box Collider 2D.
So we're going to type this box Collider 2D.
And let's make this uh first bracket and then close that up with semicolon.
And we have the box Collider 2D now.
So let's store this box Collider 2D into this box Collider 2D variable.
And let's set equal to this.
So now we have the reference, uh, for uh, basically we have this box Collider 2D as well as this
rigid body 2D.
So if I select click on this rigid body 2D as you can see gravity scale three.
So we're going to set it to zero.
But before we set we just want to disable this box Collider 2D.
So this barrel game object not gonna detect any collision if we just disable that.
And after it we're gonna set the gravity scale to zero.
And if we don't do that, it's gonna fall down due to our gravity.
So that's why we're gonna set the rigid body 2D gravity scale to zero.
So let's open up our script, and we're gonna do it inside this trigger animation function.
So whenever we're playing that animation clip, then we're gonna do that.
But, uh, so firstly we just want to set the gravity scale to zero.
So let's go to RB dot gravity scale.
And we're gonna set equal to zero F.
Basically we're going over to this rigid body 2D.
And we setting this gravity scale over here to zero.
As you can notice in our script.
And after that we also want to disable the box Collider 2D.
So we will go to Box Collider 2D.
And we're going to use dot enable dot enable.
And we're going to set equal to false.
False basically means that you just disabling that box Collider 2D.
And if you set equal to true basically box collider dot enable equal to true means you just enabling
that since we want to disable.
So that's why we're using this box collider 2D dot enable equal to false.
And now we're going to press down Ctrl S to save our script.
And now let's move over to unity.
And you will see as soon as uh as soon as this uh, barrel GameObject just gonna play that animation
clip, which is uh, you can say, uh, you can say, um, sorry, really sorry.
uh, animation clip, which is the distraction.
You will able to notice this rigid body 2D gravity scale going to be zero as well as this just going
to disable.
So let's click on this play button in the top in order to play our game.
And let's take a look on this.
So just wait a moment.
And once we're gonna attack on this paddle game object you will able to notice that.
Just wait.
And if we get closer to this parallel and then attack on it, as you can see.
Indeed.
Uh, indeed, if we select our barrel, uh, we.
And then move over to Inspector.
As you can notice, this box Collider 2D component get unchecked basically disable.
And if we move over to our rigidbody 2D, we can see the gravity scale is to zero.
It just sets to zero.
So I'm going to get out of play mode.
So after some amount of time we also need to destroy this barrel game object.
We need to destroy that.
But after how much amount of time we need to destroy that.
So for to check that out, make sure you select your game object in the hierarchy.
Then move over to your animation tab and then click over here and choose the barrel destructible and
check the time.
So as you can notice that, uh, something like uh .4.4 amount sorry, point eight.
It just uh, destroying itself completely.
Sorry.
Not completely.
Basically the playing the animation clip, which is I guess this right over here is one second.
Uh, and this means point eight second.
So after point eight second, we also need to destroy this barrel game object.
And in order to destroy that, what we're gonna do, we're going to open up our script by double clicking
sorry, clicking on it.
And we're going to use this destroy function.
Uh, so we just going over to this trigger animation function and we need to use this function in order
to destroy and this function.
As a first argument, it's going to take the game object that we want to destroy.
So we want to destroy the game object itself or destructible game object.
So as a first argument we're gonna pass this game object means referencing itself.
And second thing comma, you can specify the time.
So after 0.8 second as you seen it's completing the whole animation clip.
So you can just put the time but for different animation like port or something like other, I don't
want to destroy a specific time.
So what I'm gonna do, I'm going to create a variable because we're going to have the pod game object
as well, which will be a destructible object.
And we do know that there are the animation is going to be a little bit different.
Uh, it's it can be something like one second.
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
that.
So let's make a serialized file private and we can call.
This will be float.
And we can call destroy time.
So let's call it destroy destroy.
Sorry.
This destroy time.
Destroy time.
And by default I'm gonna set equal to something like, uh, one f or once again.
And as a second argument right over here, I'm gonna put my destroy time.
So let's put destroy time, and let's close the semicolon and story time.
We have chosen one basically means after one second, the barrel or game object is gonna destroy itself.
But we do know that we just made it a serialized field.
So we can just adjust, uh, in the inspector right away.
So I'm gonna press down control s to save my script.
And now let's move over to unity.
And for this parallel game object, I'm going to choose the destroy time, which will be 0.8.
And for the port game object it's going to be different.
So just let me show you.
So now if we go, as you can see, destroy time underneath our destructible script we can see is one
for this parallel game object.
We're going to choose point eight, since we know that this parallel game object playing the whole animation
clip of destroy after something like 0.8 seconds.
So that's why as a destroy time, I'm going to put point eight.
So after this amount of time, this parallel game object is going to destroy itself.
So let's click on this play button in the top in order to play our game.
And you will note you gonna notice that.
And we have to do one more thing and it's going to be fine because, uh, we have done a mistake already.
So we're going to talk about that.
But before we do, let's have a look.
So if I now get closer to this barrel and if we click basically attack on it, we can see indeed that
just get destroyed after 0.8 second.
But the problem is that we also gonna have part game object as well as some other destructible objects.
So I'm gonna get out of play mode.
Instead of assigning this barrel as a barrel layer, we're gonna assign it with destructible layer because
we're gonna have multiple, uh, you can simply say multiple destructible game objects.
So that's why.
So we will choose our barrel, then go over to Inspector and then click on this layer.
As you can notice we just assign it as barrel.
So we're going to click on this add layer.
Instead of calling barrel.
We're going to call it something like destructible because we're going to have multiple.
So that's why we're going to have the port and all of those things so destructible.
Sorry if I mis spelling that.
Distract.
Okay, so this is fine.
And now we're going to choose our parallel.
And we're going to assign with the layer.
So go over to Inspector and assign with destructible.
And now as you can notice we just assign it that and we're going to click on this overrides and then
click on this apply all.
So the changes you made it's going to be safe.
And let's do the same thing with our board game object.
So I'm gonna select my parallel GameObject in the hierarchy.
And I'm gonna drag a little bit far away from my player game object.
So let's choose our parallel GameObject in the hierarchy.
And let's select this mob tool in the scene view.
And I'm going to move it somewhere around here.
So let's create with the port now.
So let's move over to our project app assets and then sprites folder.
And I'm gonna move.
We have the sprite sheet right over here.
So let's click on this arrow in order to see the individual.
And let's find out the part one.
And we also have the chest as you can notice.
So we're going to talk about it later.
So let's uh find out our part first I really apologize.
To we have the parts I guess not this one.
Uh, so this one right over here.
So let's select that sprite individual sprite and drag it over to the scene view or into this hierarchy.
As you can see, we have the part.
And now what we're going to do, uh, we can make it a little bit bigger.
So we can just go ahead and choose the sprite sheet.
And then we can just make a less our pixel per unit.
But for this part game object, I just wanted to in the X scale.
So what I'm going to do.
But before we do let's name this game object to something like part.
So let's go over to Inspector and let's call it something like pot.
And we're gonna add some components to this pot game object.
First thing we're going to add a rigid body to the for gravity.
So let's click on this add component.
And let's add a rigid body 2D.
Let's type that and it's going to pop up.
And we're going to add that.
So just weight rigid body 2D.
And I'm gonna make the gravity scale to something like three.
And the mass I'm going to choose something around five and collision detection I'm going to choose continuous
interpolate to interpolate to making smooth.
And we're going to freeze the rotation about z axis.
And let's add up our box collider 2D component for collision detection.
Or we can just add any collider 2D that we like since we're gonna add box Collider 2D.
And if we move over to script, we can see we have the Box Collider 2D reference in the start of the
game.
So that's why, uh, we're gonna attach to every single game.
Object of destructible game object.
The same collider, which will be our box Collider 2D.
Since we're gonna attach the same destructible script to, uh, to all, uh, destructible, uh, game
objects.
Uh, so let's click on this add component and we're gonna add Box Collider 2D by typing that.
And now we need to edit the collider as the size of our pod game object or Pod sprite.
So let's click on this Edit Collider inside this box Collider 2D or 2D component.
And the Inspector.
And let's edit the collider as the size of our pod game object.
Something like this much.
Sorry.
So let's select the pod.
Let's click on this edit edit and let's edit this like that.
And let's move it a little bit down.
And as you can see, it's fine.
And we're gonna assign this pod game object as a our destructible layer.
Why?
Because this will be our destructible layer.
Basically this pod game object.
So that's why for that let's go over to Inspector.
Then we can assign layer as a destructible.
And we're gonna assign as a destructible tag.
As you can notice, we just already assign it.
And now we need to make the animation of it.
So let's make the animation.
So the first animation gonna be the pot idle.
So let's select the pot GameObject in the hierarchy.
Let's go to animation tab and then click on this create button.
And let's go over to assets in the top left.
Then animation other animation destructible animation.
And we're gonna call this animation clip to something like Pot idle.
So let's call it pot underscore idle.
And let's click on the save button.
And what we're going to do in this, we basically just want to play this same sprite animation from
and from start to end.
To do that, make sure you select your pod GameObject in the hierarchy.
Go over to animation tab and then click on this red button in order to capture the animation or basically
to record your animation.
Then click on this add property.
Then we will go to Sprite Renderer and let's scroll down to the bottom.
And we're going to click on this plus icon in this sprite.
And the bottom we can see.
And now as you can see we have the same sprite animation.
And we are done.
So let's click on this red button to capture the animation.
And now we need to create the destructible animation clip of this pod GameObject.
To do that, we will head over to our project tab and then assets and then sprites folder.
And we can see we have it over here.
So I'm going to select from this start to end right over here.
So all of these sprite.
Sprites are destructible.
So we're gonna hold down shift on our keyboard.
And we're going to select that and make sure you drag it top of your pot GameObject in the hierarchy
in order to make the animation right away.
So let's go to assets animation and other animation destructible animation.
And we're going to call this something like Pod destructible.
So let's call it Pod distract destructible like that.
And let's click on the save button.
And now if we I'm going to select my pod GameObject in the hierarchy.
Let's drag it in the top of our hierarchy so we can see all the time.
And if I select my pod and then move over to my animation tab, and then choose this pod destructible,
and then click on this play button.
As you can see, it's playing the animation which is destructible.
Table are destructible as you can notice.
So this basically looks fine.
And let's suppose you just want to make your board game object a little bit bigger.
I'm going to choose the ideal sprite first.
Let's suppose you want.
So make sure you select your board object in the hierarchy.
Then go over to Inspector Transform and Transform and go over to scale.
In the Y you can put something like 1.5 sorry.
In the X you can put 1.5, and in the Y we can do the same thing 1.5.
In order to make it a little bit bigger as you can notice.
So this seems pretty much cool as you can notice.
And now what we're going to do, uh, we basically need to make the transition.
But before we do I don't want any, uh, the destructible animation clip to be loop of this board game
object.
So for that we're going to move over to our project tab assets, then animation folder then other animation
folder, destructible animation folder, and we can see the part over here.
We have the part idle as well as the part destructible.
So I'm going to select both of these animation clip by holding down shift.
And then go over to Inspector.
And let's uncheck the loop time.
So it's not going to loop at all.
And now what we are going to do we can just go ahead and we can just add the script.
But before we do let's make the transition from our part idle to part Distractable.
So let's select our part GameObject in the hierarchy.
Let's go over to animator tab and let's right click on this idle part idle.
And let's make transition to part destructible.
And let's select this transition.
Let's go over to Inspector.
We're going to uncheck the has exit time as well as we gonna set the transition duration to zero.
And if we scroll down to the bottom we need to choose a condition since we're going to attach the same
script.
So we need to give the same trigger parameter name as we have done inside our game object, as you saw
earlier.
So we're going to do the same thing.
So let's move over to animator tab then parameters.
Let's click on this plus icon.
And we're going to choose the trigger.
And make sure you just name it as you have done it inside your game object.
Since we just gonna attach the same script to this pot game object as well.
So the parameter is distract.
Let's call it distract and distract.
And we're going to choose a transition.
Let's go over to Inspector and let's click on this plus icon in the condition.
In the bottom we can notice.
So now we have done it.
And what we're going to do now we're going to select our pot game object.
And let's attach the script which is our uh destructible script.
So we will for that we can just move over to our project app assets.
And then we can head over to Script Folder basically in which folder we just created that As is script.
So as you can so notice right over I have so I am I'm gonna select that script and then drag it over
to this add component section in the inspector or what else you can do.
You can simply click on this add component and you can just uh, find the component or the script by
typing the name of the script.
And the name of this script is destruct.
So we can type that.
As you can see, as soon as we type it just pop up.
I'm not gonna click on it in order to attach it twice since I already attached, as you can see.
And inside this script we can see we need the animator component and we don't have it.
So we're gonna take our animator and let's drag it over to our animator field or slot.
Now we can see we have the reference of it, and now we need to destroy this bot game object some period
of time.
So as a destroy time we're gonna choose a different number.
So that's why we just made this destroy time as public for different destructible game objects.
Just gonna have different time lapse of destruction animation clips.
So that's why.
So we're going to select our port.
Let's go over to animation tab and we're going to choose destructible.
So let's click over here for destructible.
So we can notice this one as well.
It's just playing the whole animation clip after 0.8 second.
So we're going to put as a destroy time something like .8.8.
And now it's done.
And make sure you select this part game object as well.
Make this one as a prefab.
So you will have the copy.
And we're going to paste it in our level level.
So that's why.
So we will select our part GameObject in the hierarchy.
And let's drag it over to this prefabs folder in order to turn it into a prefab.
Now we turn it into a prefab.
So make sure you just do that.
And if we just go ahead and then click on this play button, you will notice that as soon as we're gonna
attack on this board game object.
Uh, basically that, uh, that animation just gonna play, which is poured destructible.
And once the animation completely plays, then after 0.8 seconds, this board game object just gonna
destroy itself after 0.8 seconds.
So let's check that out.
Firstly, I'm gonna get closer to it and let's, uh, let's attack on it.
As you can see, indeed, after 0.8 seconds, it just destroyed itself.
And if we just destroy this barrel, we can notice after 0.8 seconds it just, uh, doing that and I'm
gonna get out of play mode.
So I hope you get the idea that how you can do it.
And it's, uh, pretty much cool to see that we have some destructible game objects in our game, and
it's really make our game too much cool.
So basically, that is the thing.
And make sure you press down Ctrl S on your keyboard in order to save your project.