Tracking clicks on a specific button

43 Views Asked by At

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.

1

There are 1 best solutions below

0
x444556 On

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.