Hi, in my current game, I’m trying to make it so that if you have a power up and you collide with a different power up, then you change to that power up.
Each power up has a timer, which is managed by this code block.
public void coolDown(float coolDownTimer)
{
powerUpActive = true;
countDown.SetActive(true);
powerUpTimer = coolDownTimer;
}
For managing countDown, this code block in the update method is always run:
if (powerUpActive)
{
powerUpTimer -= Time.deltaTime;
coolDownTimer.text = powerUpTimer.ToString("f0");
The problem lies in this area. Even though a different power up is picked up and its code working finde, the new power up is terminated too quickly, because the timer from the original power up is still decrementing.
How would i fix that? I have tried using coroutines but they gave me another problem, because I then has to yield time, which made it difficult to call toString for the count down.
this code activates some of the power ups
public void strengtOn(float timer)
{
strenght.SetActive(true);
coolDown(6);
}
public void shieldOn()
{
shield.SetActive(true);
coolDown(6);
}