Detectar Click en Canvas
{{ currentPage ? currentPage.title : "" }}
Librerías necesarias:
using UnityEngine.EventSystems;
Línea de Código
Para detectar si hemos hecho un “click” sobre un objeto de UI utilizaremos el siguiente método.
EventSystem.current.IsPointerOverGameObject()
Ejemplo de aplicación
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class MouseExample : MonoBehaviour {
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
if(EventSystem.current.IsPointerOverGameObject())
{
Debug.Log("Clicked on the UI");
}
}
}
}
Referencias
Documentación oficial EventSystem.IsPointerOverGameObject
{{{ content }}}