Giving the option to repair the ship, but at what cost?

Objective: Adding in a feature a friend suggested.

Rose Owen
3 min readJun 21, 2021

I was showing off the game to a friend and they suggested something that I thought was a good idea, so I added it!

Repair in progress.

Repair System:

While repairing you can’t move or shoot and if you get hit, it won’t give you an extra life. Makes it a good risk vs reward kind of system. This ended up being really easy to add, only 1 thing that ended up stumping me but after a bit of research and it’s fully working.

No repair for you!

Only 2 variables were needed in this one. A bool, this is used to be able to tell if we are repairing or not, which we can use to stop the movement and shooting, and the one that stumped me… A coroutine, this is to store the coroutine we are about to make, we need this to be able to stop it.

Now to check if we are repairing to limit movement, shooting, and shooting the missiles.

Now we can look for when the player presses the R key, If the R key is press we can check if there are less than 3 lives and isn’t repairing. If it is less than 3 and isn’t repairing we can set the repairing to true and assign start coroutine to the coroutine we made. Doing this will allow us to be able to stop the coroutine.

Each time StartCoroutine is called it makes another instance of the IEnumerator and without a reference to the coroutine we would have to use StopAllCoroutines(). Since we have other coroutines running this would stop those as well which is something we don’t want.

Now to make the IEnumerator. First, we want to wait for 3 seconds then call the extra life from the player and change repairing back to false.

The only thing left to do is break out of the Coroutine when the player takes damage. To do this we can just add a little bit of code at the very start of the Damage method on the player. Check if repairing is true and if it is, we can use StopCoroutine using the name we gave the coroutine and change repairing to false.

This will stop the repair from happening and give the player movement again.

Lives can be never there when you need them so this will give the player a chance to repair the damage they have received but also have the chance to make things worse.

And with that, another feature is added and as always test things out to see they are working as intended. See you in the next one!

--

--