- Home /
How can I loop through all colours in code?
Right I need to make a certain part of a material change colour the part in question is called "indicator color" and it needs to loop through the whole colour spectrum so from R-RB-B-BG-G-GR-R-RB etc. I'm very bad with this sort of coding however and I have no idea where to start. I know it requires a lerp but it also needs to loop, any help will be very much appreciated
Answer by HarshadK · Dec 03, 2014 at 09:53 AM
I'm not quite sure if this is what you are asking for but below is an example to loop through the color spectrum.
Color currentColor;
for(int b = 0; b <= 255; b++)
{
for(int g = 0; g <= 255; g++)
{
for(int r = 0; r <= 255; r++)
{
currentColor = new Color(r/255, g/255, b/255);
}
}
}
This will loop through all the available colors in an 8 bit color palette. Starting from all red shades then moving towards green to blue in the end. Also the shades will start from darker to lighter as it will start from black and end with white.
If you need specific range then you can actually set values for variables r, g, and b in the loop for specific value range you need.
Okay thanks, but how can I make effect only th indicator color shader? the rest of the material needs to remain unchanged
So you want to apply this effect to a part of the material?
yes, the indiactor shader
Shader "Custom Ambient" {
Properties {
_Color ("$$anonymous$$ain Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_$$anonymous$$ainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_AmbTex ("Ambient", 2D) = "black" {}
_Bump$$anonymous$$ap ("Bump (RGB)", 2D) = "bump" {}
_IndicatorTex ("Indicator Lights (RGB)", 2D) = "black" {}
_Indicator ("Indicator Color", Color) = (1,1,1,1)
_Glow ("Glow Color", Color) = (0,0,0,1)
_Silhouette ("Silhouette Color", Color) = (0.5, 0.5, 0.5, 1)
}
The Indicator is what I want to edit
Just wanted to point out, that this will not work in C# since you use integers in your example - use "(float)r / 255.0f" ins$$anonymous$$d.
@Lunatix +1 for pointing out.
@$$anonymous$$itsuneWarriorr he is right. He is just pointing out the fact that you need to append an 'f' in front of float value and since variables r, g, and b are int they need to be typecasted to float.
I just gave the logic and it was not an actually intended code to be copy and pasted to use as is. $$anonymous$$y apologies.
Your answer
Follow this Question
Related Questions
Change slider color to green when value is 50 2 Answers
Distribute terrain in zones 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Multiple Cars not working 1 Answer
Flat Low Poly Terrain / Script a terrain 2 Answers