//不过在点击按钮的时候 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);
}
}