Search Unity

Byte in Half?

Discussion in 'Scripting' started by renman3000, Oct 31, 2018.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Using Color32, I want to gather color.grey. In Color form it is (0.5, 0.5, 0.5, a).

    Since Color32 is in bytes, (r/255, g/255, b/255, a), and grey is half of 255 in r,g,b, and I cant divide an odd numbered byte in half, what should I do??
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    It's actually out of 256 total units - you count the 0 in 0-255 to get 256 levels. If you make it half, it's 127.
     
    Kiwasi likes this.
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,128
    If you want to set a Color32 variable to the value of a Color preset you can just do this.
    Code (csharp):
    1. Color32 gray = Color.gray;
    If you want to set a Color32 variable using floats you can do this.
    Code (csharp):
    1. Color32 color = new Color(0.5f, 0.5f, 0.5f, alpha);
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Let the engine do the conversion for you, and don't worry about it.