Sorry for the noob-ish question but this is my first time using particle systems. I created a particle system and added a script to it. In the script, the particle system has a reference to a game object. When the game object is destroyed, I want the particle system to play for 0.5 seconds and then stop playing. I set all the required values in the particle system inspector. Duration is 0.5 and Looping is unchecked. When I simulate it in the scene view, it works perfectly. It only plays for 0.5 seconds and then stops. So nothing wrong there. But when I play it in the game view, the particle system keeps looping after the game object is destroyed. Here’s the script that I added to the particle system:
GameObject theGameObject;
ParticleSystem particleSystem;
void Start () {
theGameObject = GameObject.FindGameObjectWithTag ("Player");
particleSystem = GetComponent<ParticleSystem> ();
}
void Update ()
{
if(theGameObject != null)
{
//event irrelevant to this question
transform.position = theGameObject.transform.position;
}
else
{
particleSystem.Play();
}
}
How can I change the script so that the particle system plays only once after the game object is destroyed?