- Home /
Particle system script colour
Hey,
I have a "ParticleSystem" with a "Start Color" set to be random between two colours.
Via script using:
ParticleSystem.startColor = Color.red;
The start colour of slot one will be set to red, the second slot will remain whatever it was set to in the editor but you are certainly able to access the ParticleSystem as I have successfully altered the first half of the random start colour.
My question, is there any way to set the second of the two randomised colours via script? There is nothing on the scripting page that indicates how one might access the second colour.
I was assuming something like this might be available:
ParticleSystem.startColor[1] = Color.red;
But obviously I know this refers to the second component of the particle systems colour.
Thanks in advance for any help.
Answer by anyname1 · Nov 13, 2015 at 09:10 AM
For anyone else who may find this useful, it looks like this cannot be done at run time. You'd need to access the particle systems -> InitialModule -> colorMin/colorMax, which can be found if you set your inspector to debug mode, and this does not seem possible as mentioned in the comments in the below answer page.
http://answers.unity3d.com/questions/483831/how-to-modify-particlesystem-from-editor-script.html
Answer by computas · Dec 04, 2017 at 07:44 PM
Leaving an example for future references:
ParticleSystem.MainModule main = GetComponent().main;
var startColor = main.startColor;
startColor.colorMax = anyColor1;
startColor.colorMin = anyColor2;
main.startColor = startColor;
Answer by decurtic · Mar 31, 2018 at 03:56 PM
This CAN be done, and it has been answered here: https://forum.unity.com/threads/setting-particle-system-startcolors-value-with-gradient-or-2-values-through-c.437926/
Your answer
Follow this Question
Related Questions
(SOLVED) [System.Serializable] / Inspector is not working 2 Answers
Why is Shurikan particle system variable textureSheetAnimation scripting not recognised? 1 Answer
Changing individual color of particles by C# script NOT Working? 1 Answer
Particle System Emission Rate Scriptt 0 Answers
Enabling the particle system with particle.Play(); not working 2 Answers