I am trying to change the camera background color to a specific RGBA but it seems the input only takes in the color value from the range 0-1 instead of 0-255 and 0-359 when scripting. I need this done programmatically as I’ll be changing it time to time.
I did the following conversions but the color now turns out as blue instead of yellow. Is there a way I can directly input the values instead of having to convert. Another option I tried is to use Color32 but that only takes in byte sized values.
Color yellow;
Camera cam;
float firstColorConversion = 0.00278551532f; //this is 1/359
float colorConversion = 0.00392156862f; // this is 1/255
void Start()
{
yellow = new Color(78 * firstColorConversion, 105 * colorConversion, 219 * colorConversion, 5 * colorConversion);
cam.backgroundColor = yellow;
}
I don’t know where that 359 came from, but I’ve never seen any system that uses that scale.
On Unity if you create a Color object you have to pass a float value from 0 to 1, so you only need to divide your values from the 0-255 range by 255 like joe suggested.
But that’s not the only option, you can create a Color32 that takes byte values (from the 0-255 range). Color32 is a Color too, so you can just write:
cam.backgroundColor = new Color32(r,g,b,a);
where r, g, b and a are the integer values for red, green, blue and alpha components.
Note that this doesn’t work with HSV values (the 78, 105, 219 and 5 values you used make a blue color in rgba, but something more yellowish in HSV, so I guess you’re mixing them here).