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