I have 4 buttons, which on clicking,all of them does the same thing (each displays a different string read from an array to the button's text field). I want to have a single OnClick function to keep my code clean, instead of having 4 different functions for 4 different buttons. But I need to determine which button was pressed, How to do that inside OnClick Function?
You can use EventSystem.currentSelectedGameObject defined in the UnityEngine.EventSystems
namespace :
public void OnClick()
{
Debug.Log( UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name ) ;
}