判断当前点击位置是否是UI组件,避免在点击按钮时,还继续屏幕其他操作
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ARDraw : MonoBehaviour
{
void Start()
{
}
void Update()
{
}
private bool IsPointerOverUIObject()
{
//判断是否点击的是UI,有效应对安卓没有反应的情况,true为UI
PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
return results.Count > 0;
}
}