Shields Activate
Today I developed the shield strength. My task was to develop a visualization where when the player is hit 3 times, the colors of the shield powerup reflects the damage took. How did I do that?
I first started by reviewing the lives code I had already developed. I wanted to start here because the goal is to essentially add “lives” to the shield power up. I used the if() statements similar to the lives code and changed it a bit to reflect how the shields’ “lives” would be activated. Here is the basic code I started with:

The next step was to figure out how to create the colors for the shield’s lives. Here is the idea I had in mind — purple = 3 lives, orange = 2 lives, red = 1 life. I reached out to Jared, who pointed me to a forum that already answered my questions of ‘How Do I Code Color?’ He also pointed me towards his medium blog — here is the link. After reviewing the information regarding sprite rendering, I had a general idea of how it worked. I began by creating the shield lives. For each lives, the different colors I mentioned above would correspond. I created a general default color when I first picked up the power up. Under public void ShieldsActive, I then getCompenent <SpriteRenderer> then using the RGB format, I chose the color I wanted. Once the default color completed, I went back to the shield lives code under the public void Damage. This is where I coded the shield colors for 2 lives, 1 lives… For the remaining 2 lives, I getComponent<SpriteRenderer>.color = new color, set the RGB formula to chose the colors I wanted (reference lines 154 to 161).

From here, I created an else if () statement so that when the shield reaches 0 lives, it would destroy itself. This is where I ran into a problem. I thought I could use a destroy gameobject code to get rid of the shield, however that just resulted in bugs.

Instead of the shield being destroyed, the player died instead even though I had 3 player lives remaining. Why? This is because the destroy gameobject code referenced the Player instead of just referencing the shields alone. To fix this, I removed the destroy code and replaced it with _isShieldsActive = false.


Once I did that and ran the game, everything was….