Hi there!
I can’t wrap my head around this seemingly easy problem. I have a spaceship that can fly faster (thruster), if I press shift/fire3. It sould go only faster for a certain time, e.g. until the engines are depleted. After a few seconds, when you don’t press shift/fire3, the engine is powering up again to 100% and you can shift-fast-move again.
Now this is what I got so far (I am leaving most of the script away, cause it is a massive player movement script):
public void ThrusterCooldownCalculation()
{
lostThruster += ThrusterDecreaseRate * Time.deltaTime;
if (lostThruster < maxThrusterAmount)
{
shiftThrusterMultiplier = 2f;
if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow))
animator.SetTrigger("ActivateLeftThruster");
else if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow))
animator.SetTrigger("ActivateRightThruster");
}
else if (lostThruster >= maxThrusterAmount)
{
//???;
}
}
Now, this is my though-process: I know I can use the first line of code to increase the lostThruster rate over time. It works well. I also know that I need to start the time.deltaTime in that funciton as it only gets triggered after I press Shift/fire3 and this specific function gets called. The issue I am facing now is that I can’t wrap my head around the reverse process: After the thruster is depleted (at a 100, e.g. the maxThruster amount) it should count back down as long as I don’t press Shift/fire3 again. So it is a typical cooldown effect, but I can’t make it work, since within that function, I still count up in the beginning of the code and I can’t reverse the effect…
It might be a simple block in my head, but what would you recommend?
Thanks!