Search Unity

Color(r,g,b) not working as expected

Discussion in 'Shaders' started by giantkilleroverunity3d, Feb 14, 2019.

  1. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    I have a line of code:
    Code (CSharp):
    1. tsChild.GetChild(0).GetChild(0).GetChild(0).GetComponentInChildren<Renderer>().material.color = new Color(128, 0, 0);
    2.            
    What I have found out is the R,G,B values are displaying as either 0 or 255, meaning black or the brightest of each R,G,B entry. My script is supplying the Red position with data that scales from 1 to 255. The game objects that have the color that I am changing never show intermediate color values. In the line of code supplied one can see the 128 in the red parameter position. But that level of color never displays. What does display is the brightest of red possible. If I interject a zero the gameobject display black. So it seems like a binary switch regardless of the value entered. I have long blocks on a green background. What is shown are two blocks that have a value of zero. The rest of those red blocks should display their respective shade of red by the values I set.
    2019-02-13 13_10_00-Unity 2018.2.2f1 Personal (64bit) - cuboid.png

    Am I using the incorrect coding to set the colors?
    Thank you.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    There are two kinds of color types in Unity, Color and Color32.

    Color is a float per component with an unbounded range, but generally between 0.0 and 1.0. Beyond that is for HDR.
    Color32 is a byte per component with a 0 to 255 range.

    You’re using a Color with a red value of 128, so really really bright red.
     
  3. AbdulRahim_96

    AbdulRahim_96

    Joined:
    Jan 18, 2017
    Posts:
    40
    Hello there,
    Sorry I didn't mean to disturb anyone here but I can't find the option to create my own forum? Can someone help me? I also have a question

    Thank you
     
  4. giantkilleroverunity3d

    giantkilleroverunity3d

    Joined:
    Feb 28, 2014
    Posts:
    383
    Its 'Create Thread' at top of specific forum page.