Devlog 28: Added A Charged Shot To My Game
I added a charge shot ability that the player can active by holding down the fire button.
The charged shot will consume 3 bullets and will activate if the player has enough ammo or if the ability is odd cooldown.
Cool Down UI
Ability 1 slot will fill up once the player has begun to hold down the fire button. Once the slot is filled, a penetrating charged shot will be fired once the player releases the fire button.
They’re two sliders that are stacked on top of each other. A Timer and A CoolDown. The Timer Fills while the cooldown decrements. The reason is that the time to fill is different than the cooldown time.
The Charged Shot Input
Here's the entire script. Ill break each section down piece by piece.
Initial Fire Input
We’ll first check if the
Charged Shot Cool Down Slider is empty
Time.timeScale == 1 If the game isn't paused
Ammo is empty.
If all is good then we make sure that any type of reloading is canceled. I wont be covering my reloading system here. If you like to see a vague outline of it. It can be read here.
DevLog26: Ammo And Reloading
I added a ammo and reloading system similar to the game Overwatch.
The ChargeTimer ( the variable keeping track if the player is holding the button down ) will begin to fill 1 per second. All the way to the maximum number of 1.
Releasing the Fire Button
Once released, we check if the charged timer is greater than .99f. If successful then it’ll insatiate a specially created prefab of a charged shot which will have its own tags and triggers surrounding it.
all cool downs will be set, texts will be set accordingly to update the ammo information, and the ChargedShotCoolDown will be called.
Charged Shot Cooldown Coroutine
This will decrement the cooldown slider by 10% every second. the cool down timer is .33 so its hard coded to decrement at 0.033f. This timer will not allow the player to use the ability until it reaches zero.
Incomplete Charged Shot
An else statement is attached onto the tail end of the Release Fire
If the player has not held the shot long enough. Everything will be reset and a normal bullet prefab will instantiate. There is no penalty to releasing early as this logic doubles as normal firing inputs.