Determine whether the current click position is a UI component, and avoid continuing other operations on the screen when the button is clicked
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;
}
}