Another Little Push

Jared Amlin
3 min readNov 30, 2020

This blog is dedicated to a half day Friday, once again wanting to spend some time with family for the holidays.

Custom Health and Ammo Powerups

Thursday I mentioned thinking that disabling my lasers by changing my “_fireRate” to something lengthy, was less than desirable, and it quickly caused me other issues. I was having a problem where after reloading, my slow _fireRate was still active, when I need it to reset to normal. Rather than try to fix something I was already unhappy with, I went about figuring something else out. I found a simple fix online that worked perfectly using the “return” command. So, in my “FireLaser method, one of the first things that happens is telling the shift key to fire a laser. Before that, right at the beginning, I added an if statement saying, “if (_ammoCount < 1) _ammoCount = 0; return;. This did two things. Using less than 1, being only zero is less than one, fixed an issue where my UI update went down to -1 ammo. The return states that, “if my ammo is less than 1, meaning I am out, don’t continue to the next part of the script”, which is where I enter the fire command to shift. Awesome.

Now for the shields. I needed to give my shields a life of 3, and have show a change visually when hit. This took a bit more time than I wanted it to. I got the shield health working and reloading without too much problem, but I was having a problem changing the color of the shield when hit. I saw a thread where a colleague had used ‘get component’ to change the color of the sprite renderer, so I wanted to try this route. When grabbing the sprite render you can set variables for (red, green, blue, alpha). I made the mistake of thinking this would work like how I am familiar with in Photoshop. I entered some values like (255, 60, 150, 0), but noticed no color was updating. My script was happy so I was unsure of what went wrong. I did some research and found that the adjustment here only takes a value of 1 or 0 (on or off), and the alpha dictates if it is visible (1) or invisible (0). As it turns out, I am only tinting the original color, not changing it to whatever I want. This helped me enter proper working values and that almost fixed everything. My last issue was that when I collect another shield powerup, my color didn’t reset to the original value. The fix ended up being pretty simple. I needed to change the value of the sprite renderer back to normal before the next shield kicks in. I ended up adding a reset to my sprite renderer (1, 1, 1, 1) right at the point where I also reset the shield health to 3. Shield Health = done. Now all I need is a new weapon, powerup and a properly working thruster UI reference.

--

--

Jared Amlin

I am an artist and musician, that is currently diving headfirst into game development with C# and Unity3D.