Phase 1: Shield Strength

Simon Leen
2 min readJun 17, 2021

Objective: Make the shield last for 3 hits with visuals to show shield strength.

Following on from the last post, we will use a similar scaling effect as we did with the thrusters to show the level of shield strength. The first thing we need is a private int for the shield health.

We need to modify the ShieldActivate method and set the shields health to 3, followed by calling a ShieldHealth method that we will create now.

Modified ShieldActivate method

We create the private method called ShieldHealth. In this we set a Vector3 called scaler followed by using a switch statement to check the shields health. For the case of the health being 3 we set the scaler to the original Vector3 shield size (2f on all x, y and z) and set the shield visualizers localscale to this.

For a health value of 2, we set the scaler to 1.75f on all and for a health value of 1 we set them all to 1.5f. For case 0 or no shield we set the is shield active bool to false and set the shield visualizer active state to false. We do the same for the default case.

ShieldHealth method

Finally within the TakeDamage method, we change the logic from inside the if shield is active check from just disabling the shield to reducing the shield health and calling the ShieldHealth method which changes the visualizer size to the correct size.

By implementiing it in this way, calling it form both the TakeDamage and ShieldActivate method, picking up a new shield resets the shield back to full health and scale.

Full health shield
Shield with 1 health
Shield being destroyed

In the next post, we will implement an ammo system for the player.