From Photographer to Video Game Creator — Day 13

The puzzles are getting harder and steady progress is definitely harder to make at this point, BUT in a weird way it’s getting more fun! Each element is getting trickier and trickier and I’m finding myself back tracking to previous lessons to get ideas on how to move forward.

Today, my goal was to complete my shields. My normal shield works perfectly fine, but the challenge today is to give my shield three hits before it is destroyed and display the shield health by changing colors each time it is hit. It doesn’t sound too bad, but I have no guidelines on where or how to start. The only thing to do was to start throwing ideas out and hoping that it gets me close.

The first thing I did was create three objects under the Player and gave each of them a shield animation. Within the Player code, I then created a private game object named “Shield Visualizer” with an array. Back in my inspector, this allowed me to assign my three different shield objects.

So far, so good.

The next part took quite a few tries and a whole page of sketching out ideas of how the code should be ordered. I find the toughest part to be deciding on how many variables to create. At first, I want to just make variables for everything, but I know this isn’t the best. I decided to use a combination of my “_isShieldActive” boolean and my “_shieldVisualizer” object to create an “if” statement. This “if” statement would run like a check list from start to finish while deducting one life per hit to the shields.

Once the shield loses its last life, the Shield Visualizer and the “isShieldActive” boolean is set to false. This lets the Enemy lasers know that there is no longer an active shield and the Player can be damaged. Here are the three levels of my shields at the moment. (I may decide to change the colors at a later time.)

Shield Level 3
Shield Level 2
Shield Level 1

The last step was to run the Shield Power Down Routine. The currently has a 10 second timer before it deactivates, regardless of how much damage has been taken. The tough part was reseting the shield to level 3 (max health) if the Player collected another shield powerup while the shield was already active. After A LOT of research, I found the solution by using the “stop” and “start” coroutine commands followed by a string of the coroutine.

I feel pretty solid about my progress today. I ran into a few roadblocks for sure, but I was able to work my way through them and eventually find a solution that runs smoothly. I think I will add the ability to reset the timer of the powerup to my other powerups tomorrow. I like how this works!


-Myles M.

Professional photographer on a journey to create my first video game!