Search Unity

How the heck can I adjust the particleSystem emission rate?

Discussion in 'Scripting' started by richardzzzarnold, Dec 2, 2016.

  1. richardzzzarnold

    richardzzzarnold

    Joined:
    Aug 2, 2012
    Posts:
    142
    I really don't get this new method of controlling particle emission rate. I have just spent 3+ hours looking at dozens of page describing variations of ways of controlling particle emission rate. And yet....I am still no closer to getting it to work.It is incomprehensible to me.

    All i want to do is adjust ONE variable over gameplay . The emission rate. And yet this is proving to be almost impossible to achieve. How can something so basic and vital to gameplay be turned into something so horrendous to use?.

    was currently using Unity 5.3.5f1
    just updated to 5.4 which I thought would have addressed this issue...

    current code:

    1. var SmokeParticles : ParticleSystem;
    2. var em : ParticleSystem.EmissionModule;
    3. var emitRate :float;

    4. functionStart(){
    5. em=SmokeParticles.emission;
    6. em.rate.mode =ParticleSystemCurveMode.Constant;
    7. }

    8. functionFixedUpdate(){
    9. var rate =SmokeParticles.emission.rate;
    10. rate.mode =ParticleSystemCurveMode.Constant;
    11. rate.constantMin = emitRate;
    12. rate.constantMax = emitRate;
    13. em.rate = rate;
    14. }
     
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,089
    I use .emission and it works ok for me. Couple of things I can think of off-hand:

    1) Make sure your 'SmokeParticles' is actually pointing at the instance of your emitter and isn't a link to the prefab - each instance is unique so changing the emission details of the prefab won't do anything

    2) Some Unity systems require you to set the variable back in after you've changed it so might be worth trying 'SmokeParticles.emission = em' after you've updated it.