Particles don't dissapear

I have this code and with it I want a particle spawned at my Lingon object, and after say 2 seconds the particle should dissapear/die:

var particle : GameObject;
var LingonPoint = 1;

function OnTriggerEnter (other : Collider) {
    //Get Count from LingonCounter and add points from LingonPoint
	LingonCount.LingonCount++;
	Instantiate (particle, transform.position, transform.rotation); 
	Destroy(gameObject);
	yield WaitForSeconds (2);
particle.particleEmitter.emit = false;
	
}

As you can see I use yield for 2 second and then particle.emitter false to turn it off. But I have also tried

Destroy(particle);

Nothing seems to work, the particles stay at the place where the Lingon was.

Probably easy but I am new at coding :slight_smile:

Did you activate Autodestruct on the particle system inside the inspector?

http://unity3d.com/support/documentation/Components/class-ParticleAnimator.html

P.S.
If you put the yield line after destroy, you wont get done what you need. Try putting the 2 second yield first, then destroy the object, that’s what I think you want to do.

You may also want to check out the “One Shot” option in the particle system (inspector). I dont know what kind of particle system you are trying to make, so Im making shots in the dark here.

hi pixellegolas

So when you want do destroy something you have always to do something like that:

Destroy(thethingyouwanttodestroy.gameObject);
// So in your case
Destroy(particle.gameObject);

realm_1

Ok, thanks both of you, will try these tips out

THe particle is the standard SPARKS particle so I will try to modify it. I knew I could do it but would be nice to modify in code instead so I can also have same particle forever if I wanted :slight_smile:

Try using particle.GetComponent().emit = false; instead.

I think a lot of people missed this, but particle is your prefab, not the gameObject you instantiated. It should be:

var temp : GameObject = Instantiate (particle, transform.position, transform.rotation);
and then
temp.particleEmitter.emit = false;

So long as autoDestruct for the particle system is checked, it’ll destroy itself.

Also, if you destroy the gameObject with the script on it, the yield will never run and nothing after the yield will ever complete.