So I was adding a ‘afterburner’ to my playership and at first all seemed to be working fine…then I went to code for the recovery rate so the gauge could refill gradually after you used it and something odd happened…the gauge began resetting to full instantly instead of bottoming out and gradually filling. Any ideas?
void Update() {
//set afterburner gauge to represent % of remaining afterburner.
Afterburner.value = afterBurn / maxAB;
//activate AB when leftshift is held down up to a maxspeed of 8.
if (Input.GetKey(KeyCode.LeftShift) && maxSpeed <= 8 && afterBurn > 0)
{
while (maxSpeed < 8)
//accelerate to maxspeed.
maxSpeed += 1;
//reducegauge by the burnrate.
afterBurn -= burnrate;
abActive = 1;
}
else
{ //set speed back to 5 when the AB is not active.
maxSpeed = 5;
abActive = 0;
//Afterburner recovery
if (abActive == 0)
{ while (afterBurn<maxAB)
afterBurn += Time.deltaTime;
}
}