1. 程式人生 > >UGUI 獲得點選物體

UGUI 獲得點選物體

if(Input.GetMouseButtonDown(0)){

            PointerEventData eventData = new PointerEventData(EventSystem.current);
            eventData.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            List<RaycastResult> results = new List<RaycastResult>();
            EventSystem.current
.RaycastAll(eventData, results); for(int i = 0; i < results.Count; i++){ print(results[i].gameObject.name); } }