Issues with changing light colour

If I have something like,

  if (counter == 10.0F)
  {
    light.color = Color.blue;
  }

But I want to change ‘light.color’ to a value that I’ve managed to find in the Inspector by dragging the selector around, how would I use the RGB values from this and apply them to the code? I’ve had a look at some documentation and answers and I can’t find anything that will let me do this, it just seems to be ‘Color.whatevercolour’. The RGB value that I want to use is ‘180/63/255’.

It seems like a really basic thing but I’m just having a bit of difficulty from it, I’d really, really appreciate it if anyone can help me do this.

2 Answers

2

The Color parameters are between 0 and 1 , not 0 and 255 =]

Each color component is a floating point value with a range from 0 to 1. :

I’m assuming C# from your code snippet. If you already have a colour variable in the Inspector, can you not simply assign the variable to the light colour?

public Color myColour;

void SomeMethod()
{
    if (counter == 10.0F)
    {
        light.color = myColour;
    }
}

or using your chosen values :

void SomeMethod()
{
    if (counter == 10.0F)
    {
        float r = 180.0f / 255.0f;
        float g = 63.0f / 255.0f;
        float b = 255.0f / 255.0f;
        light.color = Color( r, g, b );
    }
}

Yeah, C#. Thank you!

I did light.color = Red; but it says unknown identifier Red.

C#:

if(counter == 10.0F)
{
    Color prettyColor = new Color (0.706F, 0.247F, 1.0F);
    light.color = prettyColor;
}

What you do is get your RGB value and divide it by 255. Store these values in a Color variable. Then set your light.color to the variable.

Works perfectly, thanks!