Search code examples
c#unity-game-enginecolorsrenderer

new Color C# (in Unity)


double red = loc[1] * 25.5;
newBlock.GetComponent<Renderer>().material.color = new Color((float)red, 0, 0);

When I apply this new Color to a variety of cubes in Unity, and loc[1] is a number between 0 and 10, all of the cubes are white, rather than varying shades of red. Why is this?


Solution

  • Color uses value between 0 and 1.

    You need to normalize the given values.

     new Color(255f/255f, 100f/255f, 0f/255f);