unity check which button is clicked code example
Example 1: unity check when clicked on object
void Update()
{
if (Input.GetMouseButton(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Physics.Raycast(ray, out hit);
Debug.Log("This hit at " + hit.point );
}
}
Example 2: how to get the name of the button pressed in unity
using UnityEngine.EventSystems;
public class Class : Monobehaviour
{
public void ButtonClicked()
{
string name = EventSystem.current.currentSelectedGameObject.name;
}
}