1. 程式人生 > >Unity3D:輸出按下時,點選到的UI

Unity3D:輸出按下時,點選到的UI

PointerEventData eventData = new PointerEventData(EventSystem.current);
eventData.pressPosition = pos;
eventData.position = pos;

List<RaycastResult> list = new List<RaycastResult>();
GraphicRaycaster CanvasUI = GetComponent<GraphicRaycaster>();
CanvasUI.Raycast(eventData, list);
for (int i = 0; i < list.Count; i++)
{
    Debug.Log(list[i].gameObject.name);
}