Project 1: Space Shooter

Giving the player another chance with a life collectible

Or more points if lives are full

Lives are updated both ways and if the player is in full health they get points instead.

This is pretty straight forward, I use the same sprite for my life collectible as I did for the player, just a bit smaller in size. I use the same formula as for the other powerups, that is RigidBody2D, BoxCollider2D and the Powerup script. After all, they already have all the functionality that I want.

For the player’s script I add a new public method called LifeCollected. The method first checks if the player already has max lives and if so it calls the previously made AddPoints method to give the player 500 points.

Method to increase lives after collecting a life powerup.

If the player is not in full health they will get one life in the else-statement. After that it calls the UI Manager to update the lives’ visuals to show how many lives the player has now. Then it will also fix the damage done to the player by deactivating the damage and reactivating the thruster visuals with the SetActive method.

--

--

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