Update
{
PointerEventData pointerEventData = new PointerEventData(EventSystem.current)
{
position = Input.mousePosition
};
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerEventData, results);
foreach (var result in results)
{
if(result.gameobject == target.gameobject)
Debug.Log(1);
}
}
用这种就不用单独挂载了,本质上还是射线检测