- Home /
Rainbow Material Script Not properly running
I am a beginner unity user, and I am trying to get an objects colour to change at a constant rate. e.g. first the red is increased to full, then green, then blue. Then the red is decreased so that there is none of it in the colour, then the green, then the blue. I have about 100 lines of code for this Simple in concept task. So far there are no mistakes with it but it only goes through one step of the process. Can someone give me a simpler way of doing this? I am using gameobject.GetComponent(). It can change the colour but it does not go in a loop through all of the stages.
@truffledude12 I see in one of your questions you have been successful in achieving similar task, could you help me with this?
Answer by argentummanusbeta · Apr 14, 2018 at 04:49 PM
I've done my research, maybe try converting the RGB to a HSV e.g.:
public Renderer rend;
public float speed, value, saturation;
void Start () {
rend = gameobject.GetComponent<Renderer>();
}
void Update () {
if (rend.material.color.RGBToHSV.h == 1) {
rend.material.color = new Color.HSVToRGB (rend.material.color.RGBToHSV.h + speed, saturation, value);
}
}
With this code you only have to change to hue instead of the red, green, and blue.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Am I coding wrong for Unity C#? 2 Answers
Changing an object's material script C# 1 Answer
Multiple Cars not working 1 Answer