Learn to code by making a 2D space shooter game.
Objective: Implement Shield Strength and Shield Hit Visualization.
Before doing this we need to understand we need to allow the player shield to take three-hit and visualize when it takes a hit.
The first step lets create an int variable called shield strength inside the player script and initialize it to 3.
In the next step, we need to decrease the shield strength by one each time get hit when isShield Active is true.
The third step we need to check is if the shield strength is equal to 2 we need to do nothing.
In the next step, we need to check if shield strength is equal to 1 we need to do nothing that means no damage to the player.
When shield strength is less than 1 we need to disable the shield and set shield strength to 0 to make sure it is zero.
Now we need to set shield strength to 3 again when the shield is activated again.
Let's see the result.
Now we need to add shield visual when we get hit, Let's create a coroutine and call it ShieldHitVisual.
Now let's modify shield color when we get hit, we do this by creating a variable of SpriteRenderer called shield renderer.
Attach shield rendered of the shield in the inspector to the player script on the inspector, select player game object expand it to drag the sprite renderer to the field.
In the next step go to Shield hit visual method change the color to red wait .5 seconds return the color to white.
Last we need to start the coroutine when shied strength is equal to 2 and when shield strength is equal to 1.
Let us see the Final result.