Question by
bhayward_incrowd · Oct 12, 2016 at 01:03 PM ·
particlescolorparticlesystemparticle systemcolor change
How do I set the statColor of a particle system through script
I am trying to set the startColor of a particle system through a script. I either get the error:
Cannot modify a value type return value of UnityEngine.ParticleSystem.main. Consider storing the value in a temporary variable
or
Property or indexer UnityEngine.ParticleSystem.main cannot be assigned to (it is read-only)
How do I do this please?
Implementation 1:
foreach (ParticleSystem p in systemToChangeColor) {
p.main.startColor = myColor;
}
Implementation 2:
foreach (ParticleSystem p in systemToChangeColor) {
ParticleSystem.MainModule newMain = p.main;
newMain.startColor = myColor;
p.main = newMain;
}
Comment
Answer by s4nti4gomedin4 · Jan 04, 2017 at 04:06 PM
@bhayward_incrowd try this.
foreach (ParticleSystem p in systemToChangeColor) {
ParticleSystem.MainModule newMain = p.main;
newMain.startColor = myColor;
}
Answer by kwameopare · Jun 08, 2018 at 01:41 PM
@bhayward_incrowd Try this
foreach (ParticleSystem p in systemToChangeColor) {
ParticleSystem.MainModule module = p.main;
module.startColor = new ParticleSystem.MinMaxGradient(myColor);
}