- Home /
Changing particle emission rate via C# script
Unity deprecated a lot of methods and properties in setting up a decent effects for my game. I need to change the rate of particle emission. How am I suppose to do this?
emission.emissionRate is deprecated stop suggesting it.
Answer by Helical · Oct 23, 2016 at 02:18 PM
//does NOT work
//system.emission.rate = Random.Range (emmisionRateMin, emmisionRateMax);
//works
var em = system.emission;
em.rate = Random.Range(emmisionRateMin, emmisionRateMax);
use rateOverTime or rateOverDistance ins$$anonymous$$d.
Answer by Halfbiscuit · Feb 06, 2016 at 11:28 AM
It seems to be rather more complex to do this now but you can access the ParticleSystem
s emission variable then set the emission.rate.mode
to ParticleSystemCurveMode.Constant
.
After that setting either the emission.rate.constantMax
or emission.rate.constantMin
should allow you to set the emission rate.
Could you perhaps go into more detail as to how to do this? This is my code: private Vector3 lastPosition; private bool mouseWasDown = false; private ParticleSystem particleObjects;
private float $$anonymous$$ = 37.0f;
private float max = 45.0f;
private float dif = 8;
private float mag = 37.0f;
private float val;
private float floor = 120.0f;
private float ceiling = 1000.0f;
private float room = 880.0f;
void Start ()
{
dif = max - $$anonymous$$;
room = ceiling - floor;
particleObjects = GetComponent<ParticleSystem> ();
var em = particleObjects.emission.rate;
em.mode = ParticleSystemCurve$$anonymous$$ode.Constant;
}
void Update ()
{
if (Input.Get$$anonymous$$ouseButton (0)) {
if (mouseWasDown == false) {
lastPosition = Input.mousePosition;
mouseWasDown = true;
return;
}
Vector3 mouseDelta = Input.mousePosition - lastPosition;
mag = ($$anonymous$$athf.Clamp (mouseDelta.magnitude, floor, ceiling) - floor) / room;
val = mag * dif + $$anonymous$$;
var em = particleObjects.emission.rate;
em.constant$$anonymous$$ax = val;
em.constant$$anonymous$$in = val;
} else {
mouseWasDown = false;
}
}
Where am I going wrong?
or just keep it as curve ins$$anonymous$$d of constant and create a curve for yourself (ParticleSystem.$$anonymous$$in$$anonymous$$axCurve), then change the rate from $$anonymous$$ up to max by evaluate.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to add a variable to a prebuilt class? 1 Answer
Making a bubble level (not a game but work tool) 1 Answer
turn on off particle system 1 Answer