Image Colour change not working with anythign other than base preset colours


I’m having a problem. I have a panel I want to change the colour of its image component. Here is the line I have:

    AppBarPanel.GetComponent<Image>().color = new Color(238, 83, 80);

That, does nothing. It also does not error or warn in the debug log.

When I change it to this line:

    AppBarPanel.GetComponent<Image>().color = Color.Red;

it starts working correctly… The names colours seem to work OK but not when I specify the RGB values myself. The same happens when I create a variable a line before of type Color. if its set to a named colour, it works fine but now when specifying the RGB values independantly.

Color values should be between 0 and 1. So what you see in the inspector as 238 would be something like 0.9333. If you want to change colors like that you can create a public Color myColor; variable to be able to change it in the inspector and use it where you need it, or you can calculate it. 255 is the max in inspector so 238 / 255 = 0.9333. (not exactly sure about this kind of calculation but i think it should work - I am sure about the 0 and 1 value though)

If you want to set color as byte. Use Color32

Like this

AppBarTheme.GetComponent<Image>().Color = new Color32(238, 8, 3, 80);

But if you use Color. You have to do this

AppBarTheme.GetComponent<Image>().color = new Color(0.8f, 0.1f,0.1f,0.2f);