How to change button background color from code?

I am trying this something like ButtonElement.style.backgroundColor = new Color(91,81,65), but no matter the color value I use, the button background always changes to white. What Im doing wrong?

Color uses float numbers, so min-max values are 0f-1f while you are using 91, 81 and 65.

In your case you should use new Color(0.35f, 0.32f, 0.25f) [255/91=0.35, 255/81=0.32, 255/65=0.25]

1 Like

Adding to the above, Color32 is for when you want to use byte values to construct a colour.

1 Like

Why cant assign a Color32 to a backgroundColor property? Im getting an error

Because it’s not a property of type Color32. It’s a property of type Color. So you need to assign a Color to it, or convert a Color32 to one.