How do I auto-destroy a particle system (shuriken particle)

Hello Everyone

I have spent the entire day looking for an article that has the best answer. The particle system that I Instantiated wont automatically die after it has finished doing it’s thing and I end up with many extra particle systems on my hierarchy. I am using unity 4.

I found this article Destroying an instantiated prefab particle effect - Unity Answers that looked close but I am still getting the same issue. Here is my code:

//Inspector variables
    
    var explosion : Transform;
    var sceneManager	: GameObject;

    function OnTriggerEnter (other : Collider)
{			
	if(other.gameObject.tag == "astroid")
	{		
		//reset to position of the astroid to the top of the screen
		var script : scriptAstroid = other.GetComponent(scriptAstroid);//get script from gameObject other
		script.ResetEnemy();
		
		//create the explosion on impact
		//testing to see if explosion is loaded
		if(explosion)
		{
			var newexplosion = Instantiate(explosion,transform.position,transform.rotation) as GameObject;
			Destroy(newexplosion,3);
		}
		
		//tell scene manager that we destroyed the enemy and add a point to the score
		sceneManager.transform.GetComponent(scriptSceneManager).AddScore();
		
		//get rid of the bullet
		Destroy(gameObject);
		
	}
	
}

This has been slightly edited to take out the useless information. I can post the full if it comes down to it.

As far as I can tell, this newExplosion GameObject I created is still directly referencing the prefab and not creating an actual new or cloned instance of it.

So in short, I need a way to get this code to destroy the particles (explosions) being created.

thanks

I use this code on a prefab to make and destroy my particles after an objects gets hit, it works with Shuriken particles.

    var MyParticleEffect : GameObject; 
    
    function OnCollisionEnter(collision : Collision) {
    //call this when you need the particles to be created and destroy after x seconds
    SpwanParticle();
    }
    
    function SpwanParticle(){
    //create the particle effect
    var newEplosion = Instantiate(MyParticleEffect ,transform.position, transform.rotation);
    Destroy (newEplosion,3);
    }

As an easy way to destroy particles on finished, make a script what is attached to the particle which has a delay and then destroys the object its attached to.

basically, you cant do " GameObject " , you need to do gameObject, because GameObject is referring to the CLASS while gameObject is referring to the INSTANCE of the class, always use gameObject when your referring to something in the game.

do this:

function Start () 
{
    //script attached to a particle which has a delay
    yield(3);
    Destroy(this.gameObject); // notice the lower case g
 
}