Concurrency problem changing power ups

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;
        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)


    public void shieldOn()


In which course and lecture are you?

Well, it is not related to a course. It is a project of my own. I forgot to check which topic I wass under. I will post my question under a different topic then :slight_smile:

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms