unity if button clicked code example
Example 1: unity if gameobject is clicked
void OnMouseDown()
{
Debug.Log("Mouse is down")
}
void OnMouseUp()
{
Debug.Log("Mouse is up")
}
void OnMouseClick()
{
Debug.Log("Mouse is clicked (down then up its 1 click)")
}
// Works only if the gameobject have a collider
Example 2: unity Check if mouse clicked UI element
EventSystem.current.IsPointerOverGameObject()