Unity 5: turning particles on/off

Hi,

I checked for this problem in the archive but all answers I could find date back to 3 or 4 years ago and are clearly obsolete.
I am using Play() and Stop() to achieve this but the result is really strange.
This is what I am doing:

I want the particle system to be off when the scene starts so in Start() I have:

	pSystem = this.GetComponent<ParticleSystem>();
	pSystem.Stop ();  

Then when the player presses Fire1 particles should be activated and should be stopped again when Fire1 button is released. In Update() I wrote this:

	if (Input.GetButtonDown ("Fire1"))
		pSystem.Play ();

	if (Input.GetButtonUp ("Fire1"))
		pSystem.Stop ();

What happens is that it works but only once: after particles have been turned on and off once, pSystem.Play() doesn’t have any visible effect any more even though it is called again when Fire1 is pressed.

Any idea of what could cause this?
Thanks in advance!

Hey @robdil, so I had the same issue. After much trial and error, it looks like the combination of Play() and enableEmission is what works. Here’s a simplified thruster script attached to a particle system, seems like it would apply to your use case.

using UnityEngine;
using System.Collections;

public class ThrusterController : MonoBehaviour {
    private ParticleSystem ps;

    void Start()
    {
        ps = GetComponent<ParticleSystem>();
        PlayThrusters();
    }

    void Update()
    {
        // Thrust button pressed, start particle system
        if (Input.GetButtonDown("Thrust Forward"))
        {
            PlayThrusters();
        } 

        // Thrust button released, deactivate particle system
        if (Input.GetButtonUp("Thrust Forward"))
        {
            StopThrusters();
        }
    }

    void PlayThrusters()
    {
        ps.Play();
        ps.enableEmission = false;
    }

    void StopThrusters()
    {
        ps.enableEmission = false;
        ps.Stop();
    }
}

Hope that helps.