Using WaitForSeconds and trigger

I’m trying to make it so on a trigger it starts the coroutine and in the IEumerator i want to use waitforseconds to do something.

Right now I can do the StartCoroutine(“my method”()); in the trigger event and it works up until the waitforseconds method.

using UnityEngine;
using System.Collections;

public class PowerUpFire : MonoBehaviour {
public bool isHit = false;
// Use this for initialization
void Start()
{

}

// Update is called once per frame
void Update()
{
 
        
     

}

void test()
{
    Debug.Log("TEst");
}

void OnTriggerEnter2D(Collider2D collision)
{
    Destroy(gameObject);
    PlayerController.health = 500f;
    startIn();

}

public void startIn()
{
    StartCoroutine(waitCouple());
}

IEnumerator waitCouple()
{
    print("tda");
    Debug.Log(Time.time);
    yield return new WaitForSeconds(3);
    Debug.Log("ADD");

}

}

The issue is the placement of this line:

Destroy(gameObject);

You are marking the object this script is attached to, to be destroyed, but then you start a coroutine? That will never work. Your coroutine works up to WaitForSeconds because up to that point the script running it still exists, but when the 3 seconds have passed, the script doesn’t exist anymore so it can’t finish running.

What you have to do is wait until the coroutine finishes and, then and only then, destroy the game object. So remove that Destroy line and put it at the end of your coroutine.