0

I want to make an inventory with different categories and if a category is selected the button for that category should no longer get a overlay if it is pressed. I've tried changing the pressed.color like this:

        Button btn = catogory_inventroy.GetComponent<Button>();
        ...
        btn.colors.pressedColor.a = new Color(0f, 0f, 0f, 0f);

but then it says

The return value of "ColorBlock.pressedColor" is not a variable and therefore cannot be changed.

I've also tried assigning the value of the new color before, but still doesn't work So what can I do to fix my probleme?

The Crazy
  • 31
  • 7

1 Answers1

0

You need to assign the ColorBlock struct to the buttons colors property. You cannot modify the value of a property that returns a struct, since what is returned is a new copy of the values and not a reference.

var colors = btn.colors;

colors.pressedColor = new Color(0f, 0f, 0f, 0f);

btn.colors = colors;
hijinxbassist
  • 3,667
  • 1
  • 18
  • 23