Hello everybody welcome back to another tutorial video
Today we will be handling enemy hit points
Ready? Let's go
We will only be using assets that we have used before in our previous tutorials
So first we want to create an enemy for us to shoot at
So let's pick one from our existing character set
This seems like a vicious opponent
And then let's create a script for the enemies
called "EnemyBehavior" and open it
The only thing the enemies have to do for this tutorial is to die
I know it's brutal
All we will need is two properties
The first is a float called "Hitpoints"
and does not need a default value
The second, also a float, can be called "MaxHitpoints"
Here we will use a default value of 5
When the enemy spawns we should reset its health to be max health
The enemy only has a single purpose
and that is to de-spawn when they have no more health left
So let's create a method called "TakeHit"
with a single parameter called "Damage"
All right
Subtract their health when they get hit
And when they have no more hit points
we can despawn them with a destroy function
The same as the projectile in the previous tutorial
Speaking of the projectile let's configure it to detect
if an enemy was hit when a collision occurs
If it is we can call the "TakeHit" method
And for the sake of simplicity we will
pass along one damage
but you can have other projectiles do more or less damage
That should be it for hit points
So let's configure Unity
Add the behavior to the enemy object and hit play
Right
Let's fire at the enemy
One
Two
Three
Four
and five
Yep dead as expected
Perfect
This is about as simple as enemy hit points can be
And to be honest
it really does not have to be more complicated either
We will do a resistance slash armor video in the future
Head over to Patreon to see how you can suggest new videos
and vote on our new content
We'll leave a link in the description below
And don't forget to hit the like, subscribe and notification buttons
to stay up to date with our five minute tutorial series
Let us know what you think about this video in the comments below
Further, we're happy to answer any questions you may have
about Unity on our Discord
And that's a wrap
See you in the next one