Hide (not delete) text after given time..?

Hey guys, well I’ve read through almost every single post I could find through Google, but it just isn’t working out… I don’t get it and 90% of the answer are fixed with JS or from 20XX < 2017… which is really weird.

The following BoostPowerup class is giving my PlayerCharacter a nice little speed boost in a 2D sidescroller and its working, BUT, now I want to display a TextMeshPro Label saying “Boost activated!” for 3 seconds. I’ve tried doing it with deltaTime and subtracting something from a local variable to get a timer, I tried IEnumerators and Coroutines, I tried almost everything, but I think I am missing something… It shows the text, but it never goes away again. It just stays there.

public class BoostPowerup : Collectible {
    [Range(1, 3)] public float boostMultiplicator = 1;
    public float boostTime = 3.0f;

    
    public GameObject PowerUpInfo;
    public GameObject powerUpInfoText;
    private TextMeshProUGUI powerUpInfoText2;

    private bool active;
    
    protected override void OnPickUp(PlayerCharacter player) {
        player.Boost(boostMultiplicator, boostTime);
        DisplayInfoText();
        StartCoroutine(DisableInfoTextAfterSeconds(3, PowerUpInfo));
    }

    private void DisplayInfoText() {
        PowerUpInfo.SetActive(true);
        powerUpInfoText2 = powerUpInfoText.GetComponent<TextMeshProUGUI>();
        powerUpInfoText2.text = "Boost activated!";
    }

    private IEnumerator DisableInfoTextAfterSeconds(int seconds, GameObject obj) {
        yield return new WaitForSeconds(seconds);
        obj.SetActive(false);    
        powerUpInfoText2.text = "";
    }
}

Any help is greatly appreciated, thanks in advance dear Unity-friends!

Hey there. I’m not too great with parameters myself so I’m not too sure what the problem with the coroutine is. Would it not be easier to have something like this:

 public class BoostPowerup : Collectible {
     [Range(1, 3)] public float boostMultiplicator = 1;
     public float boostTime = 3.0f;
 
     
     public GameObject PowerUpInfo;
     public GameObject powerUpInfoText;
     private TextMeshProUGUI powerUpInfoText2;
 
     private bool active;
     
     protected override void OnPickUp(PlayerCharacter player) {
         player.Boost(boostMultiplicator, boostTime);
         DisplayInfoText();
         
     }
 
     private void DisplayInfoText() {
         PowerUpInfo.SetActive(true);
         powerUpInfoText2 = powerUpInfoText.GetComponent<TextMeshProUGUI>();
         powerUpInfoText2.text = "Boost activated!";
         StartCoroutine(DisableInfoTextAfterSeconds());
     }
 
     private IEnumerator DisableInfoTextAfterSeconds() {
         yield return new WaitForSeconds(3f);
         obj.SetActive(false);    
         powerUpInfoText2.text = "";
     }
 }

Not sure if this is what you’re looking for but see if that works.