- Home /
How do I change the startcolor.r in code?
Hi,
I need to have a particle system change slowly from a predetermined color ,in an array, to white. I thought the easiest way to do this might be have the startcolor r, g, b values in update like this.
this.particlesystem.startcolor.r--;
But it won't compile. Can anyone help me?
is it possible you need to do this
temp = particleSystem.startColor
temp.r = .. change that or whatever
particleSystem.startColor = temp
Whereas in Javacript, you can often "just change" parts of vectors such as that
@Gazer, hey, you need to TIC$$anonymous$$ AN ANSWER please to close the question. Pls don't forget and see you on the next question.
Answer by fffMalzbier · Sep 27, 2013 at 02:25 PM
how about this? So you can transition form one color to another.
public Color StartColor;
public Color Endcolor;
Color particelcColor;
float progress =0;
void Update() {
progress += Time.deltaTime * 0.5f; //speed modifier
particelcColor= Color.Lerp(StartColor,Endcolor,progress); //lerp the colors
particleSystem.startColor = particelcColor; //assign them
}
Answer by Artaani · Sep 27, 2013 at 10:45 AM
particleSystem.startColor = new Color (1, 1, 1, 1);
Ok, that tells me how to access the r,g,b. Thanks. But how do I change it slowly? Using Time.deltatime doesn't seem to work. Thanks again for helping me.
The maximum value of r, g, b, and a is 1.0, so you need to squish your numbers into that range.
color.r = ($$anonymous$$athf.Lerp(1.0f, 0.0f, Time.deltaTime / 10f)
would fade over ten seconds from the start of the game, while this one lets you start the fade at some other time:
float startTime = Time.realTimeSinceStartup;
...
color.r = ($$anonymous$$athf.Lerp(1.0f, 0.0f, (Time.time - startTime) / 10f)
Your answer
Follow this Question
Related Questions
HSV Selector? 1 Answer
Horizontal Slider Normal-Background Change Color Independently 3 Answers
3D Text - How to change colour - Doesn't seem to work 2 Answers
How to change color as flashing or blink? 0 Answers
JS changing gui box color 1 Answer