- Home /
How do I set ParticleSystem.startLifetime by Curve in script ?
According to below ParticleSystem.startLifetime reference, ParticleSystem.startLifetime can set value by "Curve".
http://docs.unity3d.com/ScriptReference/ParticleSystem-startLifetime.html
In the Unity Inspector, I can set its value by following 4 ways.
Constant
Curve
Random Between Two Constants
Random Between Two Curves
But in C# script, I can't find the way except for Constant.
How do I set its value by "Curve", "Random Between Two Constants" or "Random Between Two Curves" ?
For example following codes has error "Error : Cannot convert from UnityEngine.AnimationCurve to System.Single ".
var particleSystem = gameObject.AddComponent<ParticleSystem>();
var curve =new AnimationCurve();
curve.AddKey(0,0);
curve.AddKey(1,1);
particleSystem.startLifetime = curve;
Answer by VegaBeyond · Jul 29, 2016 at 04:01 PM
float amplitude = 1.0f;
AnimationCurve curve = new AnimationCurve ();
curve.AddKey(0,0);
curve.AddKey(1,1);
particleSystem.startLifetime = new ParticleSystem.MinMaxCurve (amplitude, curve);
Hope this works for you.
Answer by Sethhalocat · Jul 29, 2016 at 08:13 AM
instead of directly changing your curve through script, you could make the script activate an animation that'll then change the curve. By doing this you have full control to decide when the curve is activated. I hope this helps and im sorry for being so short.
for a randomization i suppose you could do multiple animations and have the animations activated between float integers in the parameters section, then have the float be randomized in your script.
Your answer
![](https://koobas.hobune.stream/wayback/20220612073928im_/https://answers.unity.com/themes/thub/images/avi.jpg)