有些时候需要点击或移动场景中的对象,但当手指首先点到UI时不能执行点击或移动操作。
这里可以使用 EventSystem.IsPointerOverGameObject() 方法。
if(Application.isMobilePlatform){
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
return true;
}
}
}else{
if(EventSystem.current.IsPointerOverGameObject())
return true;
}
但如果有个图片是全屏的,这样每次点击都会点到图片,这样就点不到场景中的对象了,这时可以做如下设置。
使图片不接受射线,这样点击时就不会检测到图片。