- Home /
Question by
homer_3 · Jun 09, 2017 at 03:58 AM ·
script.particlesystem
How to edit particle system size over lifetime curve with script?
I'm trying to add a flickering effect the the particles in the particle system, so I thought I'd use a script to toggle the size between 0 & 1 in the size over lifetime curve. So I tried
public int flickerCount;
// Use this for initialization
void Start () {
ParticleSystem part = gameObject.GetComponent<ParticleSystem>();
float length = part.main.duration;
float timeInc = 1/(flickerCount*2);
ParticleSystem.SizeOverLifetimeModule sizeSettings = part.sizeOverLifetime;
ParticleSystem.MinMaxCurve sizeCurve = sizeSettings.size;
AnimationCurve aCurve = sizeCurve.curve;
for(int i = 0; i < flickerCount*2+1; i++)
{
Keyframe kf = new Keyframe();
if(i % 2 == 0)
{
kf.value = 1;
}else
{
kf.value = 0;
}
kf.time = i * timeInc;
aCurve.AddKey(kf);
}
sizeCurve.curve = aCurve;
sizeSettings.size = sizeCurve;
}
But it didn't seem to have any affect. Is there some other way I should use to edit the curve?
Comment
your code is looking fine just make sure you have set these properties in the inspector correctly. $$anonymous$$ake sure you have select the start size curve not the vale Second one Size Over Lifetime is checked and curve is select not the value.
startsize.png
(788 B)
size-over-lifetime.png
(2.4 kB)