Delay "Destroy(gameObject)"

I have a cube which I want to function in the following manner: when the player collides with the cube, a sound plays, and when the sound finishes (three seconds later), the cube s destroyed. Now how exactly do I do this?

I know this is a little bit older but:

Destroy has a second argument where you can make it wait for seconds

Example:

// Kills the game object in 5 seconds after loading the object
Destroy (gameObject, 5);

Here is the link for the Api: API Destroy

You do this using WaitForSeconds().

It’s easier in JavaScript (Unity script), but for C# you need to create special separate function for it.

//When you want to destroy it, call the function
StartCoroutine(Die());


//And function itself
IEnumerator Die(){
    //play your sound
    yield return new WaitForSeconds(3); //waits 3 seconds
    Destroy(gameObject); //this will work after 3 seconds.
}