Slider Color

How would I cycle through all colors with 1 slider?

Ive seen Unity’s documentation on Sliders and everything I find in posts consist of 3 sliders 1 for rgb.r, 1 for rgb.g, and 1 for rgb.b. Is it possible to cycle through all of the colors with 1 slider instead of 3 sliders?

Documentation

There are a few things to consider (ie) a single slider adjust one value so combinations can’t be created. The sliders are from 0 - 255 but in script the value is from 0 - 1. You could create an array and use script to place all the combo’s in it. Then index through the array, but what you would have is around 50 shades for each primary color. Our eyes can’t tell the difference between different shades unless they are far enough apart to make a difference to us. So you would want to lower the amount of combinations so you only have 20 or 10 shades of each color.

I’m guessing you don’t care about saturation/brightness, you just want like a colour hue slider and the values to be full brightness and fully saturated. I’d write a HSB to RGB conversion, this would be my first ref for the formulas:

I created an image to explain in more detail :slight_smile:

I have a color picker like in the image and cant figure out how to create a slider for (reference A) and cycle through those colors and change (reference B)'s color?

I did however manage to select a color from (reference B’s) using raycasting to be able to change the color of another object which was part of the goal, but figuring out how to have (ref A) as a slider and change (ref B’s) color has me stumped, and stuck.

Edit:

I just had an idea don’t know if it will work but here the thought:

I’ll just turn (reference A) image into the actual slider through a gui skin. That way I can just set up 6 colors (red, blue, green, yellow, etc…) and print the slider values 0 to 255 to get where each color is related to the slider then do an if statement (if slider value >0 slidervalue < 42.5) then change (reference B) to the color red.
Since I’ll be using (reference B) for the actual color picker it will have the alpha and different color values already built in because of the multi-colored image thats above.

Hope that all makes sense and I hope it all works, I gotta wait till tomorrow to try it. So i’ll be posting back if it works or not.

That won’t really work, you’ll want to do actual colour space conversion from HSB to RGB.

The picker you’re making is set-up to use Hue (coloured bar) Saturation (X axis) and Brightness (Y Axis) ergo HSB colour space, but colour values in Unity are in RGB so you need to convert from one to the other. This is a common thing, lots of programs do it and they all use the same HSB to RGB conversion. I linked to the formula needed for that conversion above.

If implementing the formula on your own is too difficult then this might help:

http://wiki.unity3d.com/index.php?title=HSBColor

–Eric

Greatly appreciate the links now that I have the HSBColor.

How would I move forward now (trying to create a slider for reference A above)?