Assigning Points to Destructible Pieces

Esteban Ibarra
2 min readMay 16, 2021

--

After a lot of blood, sweat, and elbow grease, we now have a complete boss battle. The only thing left to do is tweak how many hitpoints each piece has to extend the battle a bit, as well as give each piece hit points. Over the next few days, we’ll go over:

  • Adding points to each destructible
  • Adding bullets to the ‘front guns’
  • Giving a proper ending and final explosion to the boss once you defeat it.

And that’s it! We’ll have a complete Boss Battle programmed! In all honesty, by this point, you can probably figure out how to do these things, but I’ll share it for completeness. Ok, let’s break out our coding environments!

Reward points to the player for destroying a destructible:

Break out your target script and let’s add a points variable:

Then you award them to the player when the destructible is destructed. :D

In the OnTriggerEnter2D, inside of the _hp≤0 check, we just add:

Player.Instance.AddScore(_points);

Easy Peasy!

While we’re at it, let’s reward the player for destroying an entire section!

Reward the player for destroying a section:

Load up BossSection.cs and add the same _points variable and give it a default of 100. You can of course assign different points to the inspector.

Then it’s just a matter of adding the same Player instance code in the CheckChildren function:

And that’s all there is to it! Tomorrow we’ll Give our Front end guns some ‘bullets’. For a challenge, try giving a few points when the player destroys a layer of objects! See you tomorrow!

--

--

Esteban Ibarra
Esteban Ibarra

Written by Esteban Ibarra

cartoonist, game artist, and wanabe gamedev.

No responses yet