Problem: The player can fire too many light balls.
Analysis: Don’t let him.
Solution: You have a limited number of light balls. (That’s what she said.) Every time you fire one, it takes a certain amount of time to recharge. This time is longer as you use them.
Since this is a student project, and you’re lost, I’ll make a quick reference implementation here which I have not tested in any way at all. I am just typing from memory and may not even be using the right syntax. This is just to give you something to debug.
Imagine for a moment that you have a limit of five balls. You fire one, and it will be two seconds before you regain that one ball. You fire another, and it will be four seconds before you regain that one, and the rest of the two seconds before you regain the first. Your last ball is reduced in power by the amount of recharge. We’ll need four variables to make this work.
public int maximumBalls = 5;
public float rechargeSeconds = 2.0f;
public int currentBalls = 5;
private float currentCharge = 1.0f;
In your Update() method, you charge up the balls like this:
if(currentBalls < maximumBalls) // only recharge under max ammo
{ // algebra on word problems! YES IT WAS USEFUL
currentCharge += Time.deltaTime / // Divide frame time by...
( rechargeSeconds * // two seconds per...
( maximumBalls - currentBalls ) // ball less than maximum
);
if(currentCharge >= 1.0f) // If we're done recharging...
{
++currentBalls; // Add one ball
if(currentBalls < maximumBalls) // if we are still charging
{
currentCharge -= 1.0f; // subtract the full charge
}
else
{
currentCharge = 1.0f; // cap the charge at full
}
}
}
All the rest of your Update() method can stay the same. Now, when the player fires a light ball, you simply wrap that code into an if(currentBalls > 0) { } block and --currentBalls somewhere in there. If you want the light balls to be dimmer based on the charge status, you can multiply your light’s intensity by the currentCharge when you instantiate it. If you don’t, well, don’t do that.
Most importantly, play with this and use player feedback to find what makes the game the most fun. Tweak and poke at the system until you’ve made it as good as you can manage.
And don’t be afraid to throw it out if you have a better idea. It’s your game.