Changing Camera Background to custom color

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;

Have you tried [SerializeField] Color yellow. If I understand what you want that should allow you to set the color in the editor.

Edit: I’m just going to quote my comment:

Ok I understand whats going on now, the values you are trying to set are actually HSVA values not RGB.

(78,105,219,5) (HSVA) is (192,219,129,5) in RGBA.

RGBA is all in the 1-255 range by the way.

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).

you don’t have to calculate colors , unity do it for you. . .
read the documentation

If you want to introduce your own RGBA Color you need to divide by 255.

public Color myColor;

myColor = new Color(192.0f/255.0f, 219.0f/255.0f, 129.0f/255.0f, 5.0f/255.0f);

Also note that 5 for alpha is not very logical (for a camera background).