- Home /
Colors Seem all wrong when I set them in RGB
So I set a color = new Color(10,40,90); thinking I'm going to get a dark blue but I get a bright white.
Pretty much I seem limited to only the colors that can be found doing color.red or w/e
Whats going on here?
Answer by robertbu · Sep 28, 2013 at 05:26 AM
Color in unity are expressed as floats in the range of 0.0 to 1.0. So your blue color would approximately be
color = new Color(.04f, .16f, .35f);
Wow, okay. For some reason I assumed it would be the normal 0 - 255 well that explains it so I pretty much had it as 255 255 255. Is there a handy conversion chart? or is it just a % thing where every 50 is roughly a .2? And thanks.
No conversion chart...just value/255. There is a Color32 in Unity which is 0-255. It can be implicitly converted to a Color. But most things you interact with will be of type Color not Color32.
@robertbu Thanks for your answer but still have to indicate the values are floating point or Unity spits out compile errors. i.e.
color = new Color(.04, .16, .35);
//becomes
color = new Color(.04f, .16f, .35f);
Answer by Bunny83 · Aug 15, 2016 at 02:08 PM
Alternatively you can now also use the "Color32" struct which represents an RGBA value that consists of 4 byte values in the range of 0 - 255. Color and Color32 have implicit casting operators so they are automatically converted into each other.
// C#
Color someColorVar;
// somewhere else:
someColorVar = new Color32(10, 40, 90, 255);
Here the Color32 is implicitly converted into a Color.
Unforunately "Color32" doesn't have an additional constructor that takes only 3 values as "Color" has. So you always have to explicitly specify the alpha value. However you can directly use byte values
Your answer
![](https://koobas.hobune.stream/wayback/20220613114934im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Issues with changing light colour 2 Answers
Material color won't update! 2 Answers
Switch between random colors 4 Answers
Color index operator not working properly 1 Answer
Change Color in C# with RGB Values? 4 Answers