Destroying an instantiated prefab particle effect

I have a global inspector variable
and I can declare it either this way:

var explosion       :GameObject;

or this way

var explosion       :Transform;

I then also have an explosion effect made with SHURIKEN tied to my script via the inspector.

When I call on this explosion I instantiate it like this (in the place of my object), to make sure that explosion is there in the inspector

if(explosion)
{
Instantiate(explosion,transform.position,transform.rotation);
}

How do I remove the effect after it has done its job ?

I tried:

if(explosion)
{
Instantiate(explosion,transform.position,transform.rotation);
Destroy(explosion.gameObject,3);
}

and I got:

Destroying assets is not permitted to
avoid data loss.

Does anyone have an idea ?

if(explosion)
{
GameObject newexplosion = (GameObject)Instantiate(explosion,transform.position,transform.rotation);
Destroy(newexplosion,3);
}

You need to store what you instantiated in a temporary variable so that you can talk to it afterwards.

I’m very sorry but I’m using Shuriken particle system and not the old legacy elipsoid particle emitter that had the autodestruct button. If I used the old one I wouldn’t have that problem but I do not want to use an outdated system while learning unity 3.5.

1.unchecked looping from particle system editor 2.create a transform variable in your script as public(example explosionTrans)and set your particle object from editor. 3.now in your update method explosionTrans.particleSystem.transform.position=this.transform.position; explosionTrans.particleSystem.Play();

if(explosion)
{
var newexplosion : GameObject = Instantiate(explosion,transform.position,transform.rotation);
Destroy(newexplosion,3);
}