GameDev : Player Damage Visualization (Part II)!!

Matteo Lo Piccolo
3 min readJul 4, 2021

--

Ok, I try to solve this problem with a Switch statement.

Inside Damage, I create a Switch based on _lives
and manage every single cases

Since we have a _lives based Switch, we handle the Die method here, it is useless to have a Switch for two conditions and create an If Statement for only one.
So let’s comment out momentarily the part with If, we move the two line of code inside the case 0 into Switch, and test it!

And it seems everything work without a problems!
Again, this is my method, not the best and not the right one, it is simply ONE METHOD TO SOLVE THESE PROBLEMS.

I’m not create animation yet, so I implement now.

After you have the animation, we can copy component in the other object

Let’s test it

Everything about Damage visualize works, but as you can see, we have a little BUG.
Since I set the enemy’s speed to 0, when we destroy it, even if it explodes, it’s STILL THERE.
You Remember? We had set the Destroy after 2.6f seconds…

It’s not a big problem, but we need set enable = false some component of Enemy (probably the BoxCollider2D), so after it explodes it cannot damage us again.

To try, we take the reference of BoxCollider2D inside Enemy script, initialize it in Start and make the classic check for NULL Reference, then we use it after we set the speed to 0.

We don’t need it here

Because the Enemy is Destroyed immediately

Let’s try and see what happen

It seems works, even if I stay into explosion, my lives wan’t go down

--

--

Matteo Lo Piccolo
Matteo Lo Piccolo

Written by Matteo Lo Piccolo

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!

No responses yet