Attempting to code a simple healthpack powerup

I’m trying to understand the code for the logic I’m trying to implement, but it’s not cooperating like I expect. Essentially, a player collides with a box, and when that triggers, it calls the function GetHeal();
Currently what happens is the player is healed, the gameObject is set to inactive, but never gets set back to active after the WaitForSeconds. I’m sure there’s a better way to do this, but I figured this was the easiest. Any help is appreciated.

float healAmount = 20f;

    public int GetHeal()
    {
        StartCoroutine(RespawnPowerUp());
        return healAmount;
    }

    public IEnumerator RespawnPowerUp()
    {
        gameObject.SetActive(false);
        yield return new WaitForSeconds(1);
        gameObject.SetActive(true);
    }

When you post code on the forum, make sure to use Code Tags .

When an object is inactive, it won’t run Update loops anymore. Since coroutines are checked after Update, it won’t run your coroutine anymore.

As Panda points out, turning this gameObject off simultaneously kills the coroutine.

Instead, a simple float variable set up as a cooldown timer is perfect for this.

In your case the cooldown timer being nonzero would mean “I am still recharging, you can’t use me again yet…”

Cooldown timers, gun bullet intervals, shot spacing, rate of fire: