1

Working version of changing the color of an object by component "Image":

 public Button bth;

 public void Example() {
   bth.image.color = Color.black;
 }

Color.black(Native struct Unity):

public struct Color {
  // Summary:
  //     ///
  //     Solid black. RGBA is (0, 0, 0, 1).
  //     ///
  public static Color black { get; }
}

However, if I want to create a custom color, it doesn't work.

public void Example() {
  Color customColor = new Color(255f, 134f, 36f, 255f);
  bth.image.color = customColor;
}

The object doesn't change color. In the inspector, showed a white color(255,255,255,255)

The only solution that I found is to create a public variable. Then in the inspector to adjust the color.

public Color customColor;
public void Example() {          
  bth.image.color = customColor;
}

customColor in Inspector

Igor Cova
  • 3,126
  • 4
  • 31
  • 57

0 Answers0