//不過在點選按鈕的時候 myEventSystem.currentSelectedObject.gameObject.name可以傳回對象,如果是image控件的擷取不到
方法1:不能傳回具體控件除非button
public class IsRayUIOver : MonoBehaviour {
private EventSystem myEventSystem;
void Start () {
myEventSystem = GetComponent();
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
//Debug.Log(myEventSystem.currentSelectedObject.gameObject.name);
if (myEventSystem.IsPointerOverEventSystemObject())
Debug.Log("目前點選在UI上");
else Debug.Log("目前沒有點選在UI上");
}
}
}
方法2:
1.給camera添加physics Raycaster,可以調整EventMask,UI
2.将需要接收選中控件添加腳本
public class TestClickHandler : MonoBehaviour ,IPointerClickHandler{
public void OnPointerClick(PointerEventData data)
{
Debug.Log("按鈕事件被點選"+this.gameObject.name);
myUIClick(this.gameObject);
}
}