-1

I am new in unity. I have 4 buttons in my scene and each button has the same script.

In the script, I check the mouse click on the button and change its color. When you click on one of the buttons, each button changes color. It looks logical, but how can I change the color of the button on which the script is added?

UPD: I used this:

button.onClick.AddListener(delegate () { Click(); });

Thanks everyone for the help.

Operator
  • 27
  • 5
  • You would have to give each button an identifier (unless unity does this automatically) and then search for the button with that identifier and update it – Roe May 01 '23 at 10:39
  • Can you post your code and the inspector of one of the buttons? – Daniel M May 01 '23 at 10:45
  • How to track a click for a specific identifier? I call this function in an Update: `if (Input.GetMouseButtonDown(0)) { _buttonImage.color = Color.red; }` – Operator May 01 '23 at 11:35

1 Answers1

0

You can add private Button btn; to your class and then btn = GetComponent<Button>(); in Start() Then you can access the button from the click method and change its color.

x444556
  • 57
  • 7