Allowing Shields To Take 3 Hits Unity3D

Pete Thomasberger
2 min readJun 20, 2021

Objective: Allow the Player’s shields to take 3 hits before being deactivated.

Step 1: In the Player script, create a private int variable called _shields and assign it a value of 3.

Step 2: In the Damage() method, within the first if statement that checks if the _isShieldsActive bool is true, decrement the _shields variable by 1.

Step 3: Within the if statement, create a new if statement saying, if the value of _shields is less than 1, set _isShieldActive to false, and set _shieldVisual.SetActive to false. This will bypass the main if statement, allowing the Player to take damage, and turn of the Shield animation.

Step 4: To show a visual of the Shields being depleted, after the _shields variable is decremented, create an if statement checking if _shields equals 2, change the Shield color to green. Then create an else if statement checking if _shields is equal to 1, change the Shield color to red.

--

--