Destroy Instantiated Game Object

Hello! I can’t seem to figure out how to destroy an object once it was instantiated!?
I am creating a custom animation called white puff which shows up once i shoot another game object.
but then i want to be able to destroy the white puff after a certain time (once the animation is done playing)

In one of the tutorials this yield and Destroy code seemed to work but it was used in an update function…
any help on what is the proper way to set this up?

=============================================

var whitePuff : GameObject;

var sound : AudioClip;

function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == “bullet”)
{

AudioSource.PlayClipAtPoint(sound, transform.position);

Destroy(gameObject); //Destroy

// Instantiate the game object at the same position we are at
var clonePuff:GameObject = Instantiate(whitePuff, transform.position, transform.rotation);
yield WaitForSeconds(2);
Destroy(clonePuff.GameObject);

}

}

I think your second destroy call has a typo. The first “G” has to be lowercase to refer to the actual gameObject. In fact i think you only need the “clonePuff” as a parameter in that call.

Other thing is that Destroy() can take up two parameters. the first is the object or component you want to destroy and the second a time frame before the destroying take place. so it would look like:

Destroy(clonePuff, 2.0f);

And you could get the time from that object instead putting a fixed ammount of time. If clonePuff has a particle system attached you could go:

Destroy(clonePuff, clonePuff.particleSystem.duration);

Good luck!

U r awesome :slight_smile: THANK YOU! my white puff is now removed once its done playing…

Glad I could help.