300x300 크기의 이미지에서 정중앙에 클릭하면 150,150의 좌표를 가져옴(피벗이 0,0 기준)

왼쪽 최하단을 클릭하면 0,0의 좌표를 가져옴.

public void OnPointerClick(PointerEventData eventData)
{
	if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent<RectTransform>(), 
		eventData.position, eventData.pressEventCamera, out Vector2 localCursor))
		return;

	Debug.Log("LocalCursor:" + localCursor);
}

 

출처: https://answers.unity.com/questions/892333/find-xy-cordinates-of-click-on-uiimage-new-gui-sys.html

+ Recent posts