Solved: Destroy command not working

In my FPS, a particle is created at the enemy object’s position every time the enemy is shot(which is checked with a raycast). The particle is a prefab that is instantiated, and there is a script attached to it that is supposed to destroy the particle 2 seconds after it is created. Here is the contents of the script(called destroyOverTime):

//Inspector variables
var lifeSpan : float;

function Awake(){
Destroy(this, lifeSpan);}

The variable lifeSpan is set to 1 in the inspector view. However, the particle prefab is never destroyed; each one is always present in the hierarchy. I’m not sure why this is not working, because as far as I can tell the code is correct. Can anyone help? Thanks for your time.


means the actual object you are referring to. In this case, the object is the script and not the particle system.

Use Destroy(gameObject);