How can I play an explosion animation?

I want to instantiate an explosion prefab, so an explosion animation (created as an 8-frame animation) is played, then destroy the instantiated object. I can not achieve my goal as I don’t know how to destroy the explosion object once the animation is finished.

All tutorials I’ve seen related to explosions instantiate a particle effect. I’d like to know if this is the only way to do it (or the only PROPER way to do it) or if what I’m trying makes any sense.

In case I should create a particle effect, what should I do to get the same result as in a “standard” animation frame by frame?

alternative way:

public explosionTime; // set it in inspector

private void Start() {
   Invoke("DestroyMe", explosionTime); // shedules derived call 
}

private void DestroyMe() {
   Destroy(gameObject);
}

private expTimer : float;
public expTime : float;

function Update () {
   expTimer++;
   if (expTime < expTimer/60){
      Destroy(GameObject);
   }
}

JS

In inspector set expTime

Hello,

I suggest you to make a prefab by dragging the gameobject into the prefab folder and instantiate it where you want to run the explosion Animation. After the instantiation of prefab to delete the animation by appling “Destroy(explosion(Clone))”. Because the prefab is now instantiating in the form of clone.

Link : Unity - Scripting API: Object.Instantiate

Hope this will help you.

Thanks