2D Shooter: Fixing the Issue with Charging; Cooldown Complete!
So in the last article I came across an issue where my charge routine wasn’t working. What would happen is that if I released the shift button before it hit zero, the variable keeping track of the charge would only increase by one before stopping. I knew the problem had to be where the charge routine was getting called, or in the routine itself.
And it was the latter.
I first tested by adding Debug.Log(“charging”); into the while loop to see if the routine was getting called at all. If it was working properly, the console would display “charging” five times. It only displayed once.
That’s when I figured out that one of the conditions was becoming false after one pass through the loop. The only one the made sense to me was the Input command. I got rid of it, and found that it finally began charging.
One problem came up though, if I pressed the shift button again before the counter reached 5, it wouldn’t stop charging and it would be decreasing and increasing by one at the same time. To fix this, I changed added “Input.GetKey(Keycode.LeftShift) != true” in the if statement where the routine gets called.
Now the thrusters work and have a proper cooldown system!