Doing a little clean-up.

It’s been about a week since my last article. I went on vacation with my family and now I’m ready to wrap up this project. Today I’m fixing a couple of tiny bugs that were bothering me. The first was when the player collected the health pickup when they already had full health. When this happened, the player had 4 lives instead of 3 as intended. The fix to this was in the ‘Player’ script at the ‘AddHealth’ function.

The next issue I had was when the player had a shield and it had already taken a little bit of damage to the shield, then they collected another shield. What happened before was that the shield value went back to 3, but the appearance of the shield stayed at the damaged values. All I did to correct this was to force the color change in the ‘ShieldActive’ function in the ‘Player’ script.

Since my Post-Processing settings have colors looking a little odd, mine is set to cyan, which actually makes the shield yellow. Again, this is just how I have my post-processing settings. The color you will choose will be whatever color you set at Case 0.

I also worked on the enemy a little. Before, the enemy was able to hurt the player a second time after they collided with the enemy. The enemy also was able to sometimes shoot again after being killed, causing phantom lasers to appear.

To fix the enemy shooting after death I created a bool checking if the enemy was alive and placed it in a few places.

In ‘Update’ I added to the if statement for shooting.

And also when the enemies die in the OnTriggerEnter2d, I set the bool to false before calling the ‘EnemyKilled’ function from the ‘SpawnManager’.

To fix the issue where the player was being damaged by the enemy collision twice, I added a destroy collider 2d to the player portion of the OnTriggerEnter2D function.

Another thing I did was change the color of the aggressive enemies when they became aggressive. In the ‘Enemy’ script, I created a SpriteRenderer variable to control the color since the enemy uses a sprite renderer instead of a material.

Need to make sure to reference it in ‘Start’.

Then in my ‘AggressiveEnemy’ function, I change the color when the player is within range.

There is a couple of other aesthetic things I changed as well, such as having the thrusters only being on when the player is pressing the thruster button, and updating the damage appearance to the player when they collect a health powerup.

First off, let’s tackle the thrusters. First, we need to create a Game Object reference variable and set it in the Inspector.

Now, in the ‘Thrusters’ function, we will just set the object as active when pressing the button and disable it when we aren’t.

To correct the engine appearances when taking damage and picking up health, I chose to create a new function to check the players’ health, and based on the health, will determine what engine damage is set to active. Here is what the ‘Damage’ function and the new function look like now.

And finally, I add the ‘UpdateEngines’ function to ‘Update’.

That’s what I wanted to work on today and get back in the swing of things. I have just a few things left to add to the game and it will be completed. Really looking forward to that feeling. Until next time.