Color Codes

Using the documentation:

I have been attempting to create as many colours as I can.

Most have been added for me such as ‘Color.blue’ and ‘Color.yellow’ etc.

However im struggling to create slightly more complex colours such as orange, purple or shades of green.

I tried using fractions within the ‘Color(x,x,x,1)’ however this did not work and simply gave me usual colours or black.

Can anyone help clear this up as the documentations doesnt show me how to make colours not present within the system.

Not much to say other than check the docs and make sure the RGBA values create the color you want:

http://unity3d.com/support/documentation/ScriptReference/Color.Color.html

If this isn’t working can you post some code you’re trying and the color you were expecting with said code?

Well yellow is said to look like this:

I tried ‘Color.yellow’ and it worked fine which is great.

However, as a test to see if i could replicate the colour using its RGBA values:

Color(1, 235/255, 4/255, 1); //As shown in the documentation above

It gives me the colour red instead.

Although this isnt a problem as i can simply use ‘Color.yellow’ to achieve yellow, it is problem as if it had of worked, i could have used a similar approach to display orange and purple.

You are dividing integers, which will give an int as a result. Try 235.0/255.0

Wow, that’s some stupid code in our docs :wink: - that code is trying to divide two integers, which for the G value is equalling zero. You should use floating point values for this:

That would roughly be the color on that doc page…

ahhhh damn, I was going about this totally wrong.

Because of the documentation i didnt think it was possible to make a colour with yellow in it (orange) without using fractions.

Thanks. This makes things 100000x easier.

so basically color is not the same as inspector. instead 255 is equal to one and 128 is equal to 0.5 and so on. is their a way to convert the inspector values into the correct numbers, if not i could always make a little calculator tool

Well, no, the inspector is an abstract representation of the color and doesn’t use any particular numbers; the OS X color picker for example can use RGB, HSB, CMYK, or grayscale. Even the Unity color picker uses both RGB and HSV.

You can use Color32, which uses 1 byte each for RGB, so you get 0-255, rather than using floats like Color does (this also means Color32 uses 4X less memory than Color).

–Eric

actually i now remember something about this from school, any way i thought i would quickly do a sort of color chart for people interested, i may or may not make a tool to do this to be honest i probably wont use it much anyway.

so here is what each number represents to the inspectors color, so get the color you want in that and use this to get the color,

0 = 0
0.1 = 26
0.2 = 51
0.3 = 76
0.4 = 102
0.5 = 128
0.6 = 153
0.7 = 178
0.8 = 204
0.9 = 230
1 = 255

each value has a 26 digit gain, so 0.55 would be 128 + 13 as the 5 on the end is half of 26, and you can pretty much work it out from there.

ahh cool ill have a look at color 32 especially if it uses less memory, cheers