Repairing our ship

Jordan Evans
Jun 12 · 2 min read

Today, we are going to take a look at how we can create a new powerup to repair the damage dealt to our ship. To start, we need to create a new powerup sprite to work with and attach our rigidbody, box collider, script, animation and audio clip to it, like we have with all of our other powerups. From there, we can go into our player script and add a couple new voids that will tell Unity how we want our repair system to work:

Our top method is telling unit that as long as we are equal to or lower than 2, and not equal to 0, we will want to add to our lives, update the life UI graphic we have in place and run the HealthRepair method we have created underneath. As for the Healthrepair method, we will create a switch statement that will go through the 3 different life states we have that doesn’t include to demise of our ship. As we are healing the ship, and we have animations in place for when we take damage, we need to be sure to trigger those graphics to false or true depending on the status of our ship.

From here, all we need to do is add in a new case to our switch statement in the powerups script to attach our new repair sprite to:

Finally, we just have to increase our range in the spawn management script to account for the spawning of our powerup:

Once we have all of this set up, we can go into our Editor and check to see if it works properly within the game:

Just like that, we now have a method to repair our ship in place and it changes our life counter along with how the ship’s look.

Nerd For Tech

From Confusion to Clarification

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Jordan Evans

Written by

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.