I’m working on a game that needs to control
ParticleSystem in runtime.
But the problem is that I can’t change the
ParticleSystem / ColorOverLifetime / Gradient in runtime and with scripts. Here is my code to do that which didn’t worked :
ParticleSystem.ColorOverLifetimeModule col = backgroundParticleSystem.colorOverLifetime; Gradient gradient = new Gradient(); GradientColorKey colorKeys = new GradientColorKey; GradientAlphaKey alphaKeys = new GradientAlphaKey; colorKeys.color = backgroundParticleStartColor; colorKeys.time = 0f; colorKeys.color = backgroundColor; colorKeys.time = 1f; alphaKeys.alpha = 1f; alphaKeys.time = 0f; gradient.SetKeys(colorKeys, alphaKeys); ParticleSystem.MinMaxGradient gr = col.color; gr.gradient = gradient;
In this code I just tried to change the gradient by remaking a new one each time and resetting its
I’m sure that the gradient is setted correctly but somehow the particle system isn’t updating.
I think your last two lines are the issue. Shouldn’t it be
col.color = gradient;
instead like in the doc?