Adding Gradius Like Shield Power Up To My Game

Overview

A new variable named shield health was added to be able to set the amount of health the shield can have (max 3).

Our shield game object reference will also be used to scale the shield down by reassigning its transform.local scale

Modifications made in ShieldAcive() and Damage() method to revolve around the use of our new shield health integer.

ShieldActive() Method

This method will return the scale of the shield game object back to its original scale and reassign shield health to 3. It will also set the game object active to display visuals. This method is redundant when initially called, but its useful afterwards.

Damage method shrinks the game object and decrements the shield health integer. I need to return the original values to the shield game object so that the shield will work properly.

Damage() Method

The damage method is only called when the player has collided with the enemy’s laser or the enemy themselves.

The method will first check if shield health is greater than 1. If true, then shield health and scale will decrement.

use the shield game object reference to adjust the scale of the shield

added a int variable that will be decremented when the player is hit. The scale of the shield will shrink and shield health will decrement. The method execution will be interrupted by a break. This will occur until shield health is decremented lower than 1.

Once shield health is lower than 1, the game object is disabled and method execution will bypass our initial shield if statement.

Result

Thanks for tuning in, till next time

-Vix

--

--

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