Anonymous
Anonymous

Reputation: 53

Unity, getting the name of the UI button

Tell me, please, can I get the name of a UI-button in Unity from the method which is hung on my button (OnClick())? How?

Upvotes: 0

Views: 3690

Answers (1)

Senior Guru
Senior Guru

Reputation: 56

  1. Add Event Trigger in Inspector to your Button
  2. click Add New Event Type and add a pointer click event.
  3. drag your gameobject containing this script in the script area.
  4. assign the below function in the function area.
  5. assign the button in the parameter area:
    public void OnClicked(Button button)
    {
        print(button.name);
    }
    

Upvotes: 1

Related Questions