Search Unity

Color(r,g,b) statement not working. Color.green does.

Discussion in 'Editor & General Support' started by giantkilleroverunity3d, Apr 16, 2020.

  1. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    I ran across this today. Have never tried the RGB entry.
    Code (CSharp):
    1.  
    2. public void CheatGreen(Text m_TextGreen, Text m_TextYellow1, Text m_TextYellow2)
    3.     {
    4.         //Green
    5.    
    6. m_TextGreen.color = Color.green;//works
    7. m_TextGreen.color = new Color(135.0f, 245.0f, 15.0f, 255.0f);//does not work
    8.        
    But I need to supply my own colors.
    Thanks in advance
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    The RGBA values for Colors range from 0 - 1 instead of 0 - 255.
    Confused me at first as well, and I'm still not the biggest fan of it.
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    If you really want to use 0-255 values for colors, I'm pretty sure you can just use a Color32. For example:
    Code (CSharp):
    1. m_TextGreen.color = new Color32(135, 245, 15, 255);
     
  4. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    Well too late now. I am pushing to Play store. :cool: But thanks to both of ya!
    I have been pushing code and testing for 2 weeks now. I have got to stop adding and get this gone. Other projects beckon me and summer is here so no real snowed in time anymore.