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;
}