Reduce Particle system

I want the particle system to reduce (example: 10 to 0) after I click button.

How do I do that?

Hi @WANNIK,

For this you need to create a script to control the emission on your ParticleSystem.

Once that script is created, attach it the GameObject with the ParticleSystem component.

Some sudo code

  • Get Particle System from your GameObject
  • When Left mouse button is pressed
  • Amend the particle systems max particles
public class ParticleController : MonoBehaviour
{
    private ParticleSystem _particleSystem;

    private void Start()
    {
        _particleSystem = GetComponent<ParticleSystem>();
    }

    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            ParticleSystem.MainModule m = _particleSystem.main;
            m.maxParticles = 0;
        }
    }
}

Before posting, please use google first. There will be many examples of how to do what you’re asking.

There are also official Unity docs available outlining the amendment of the particle system using code.

Hope that helps!

I already google it but I can’t found the exact code because, the problem is I want my particle system to loop then after I click a button then the particle system will reduce.

Thank you so much for answering, but another problem come out before I can see if the coding work or not.

error called NullReferenceException: Object reference not set to an instance of an object suddenly shows in my project

public ParticleSystem firePS;
public Button btnSweep;
public GameObject panel;

void Start()
{
    firePS = GetComponent<ParticleSystem>();
    btnSweep = GetComponent<Button>();
    panel = GetComponent<GameObject>();
}

void Update()
{
    if (btnSweep.enabled == true)
    {
        ParticleSystem.MainModule m = firePS.main;
        m.maxParticles = 0;
        Debug.Log("done");
    }
    else gameObject.SetActive(true);
}

One more question how do I display panel after the particle system stop ?