Developing a final boss battle: Cycling through destructable sections.


I also put a script on the section called BossSection.cs. Its only job is to look out that there are no more objects inside of it and let the boss script know it's empty; This is done with the transform.childCount command. Just check if it’s 0 and we’re good to go!

Editing lists can only be done by the originating class it seems.

For whatever reason, I had a lot of problems working with the List array. While it would accept pruning at the boss level, if the child script would ask for it, it would throw an out-of-range error, even if the child script ran the method inside of the parent. If anyone knows why this happens, and how to get around it, I’d appreciate the info.

Event — part 1:

I got around this by creating an event where the section would announce its empty and give its identification. These are the first two lines of the code, setting up the event.

Make sure the announcement is done only once:

Each section is given an id in Unitys inspector and we set up a boolean so we only make the announcement once. Before, the script would constantly be announcing the event but once the boolean gets switched, then it sends the event no more! (A very grateful thank you Paul Marsh for seeing this. I was befuddled for days wondering why 1 bullet from the ship was taking out several sections!)


Event — part 2:

This is the other half of the event, we now assign the IgnoreSectionNow function to the deleteSection in the Section script.

How to properly prune Lists:

Here’s the important part. If you’re cycling through a List, you just can’t use Remove or RemoveAt because things will shift and throw everything off. There are several options, but going through the List one by one backward using a for loop and *then* using RemoveAt is a safe way to do what we want.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Esteban Ibarra

Esteban Ibarra

cartoonist, game artist, and wanabe gamedev.