using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class DIANJI : MonoBehaviour, ICanvasRaycastFilter { /// <summary> /// 要点击的按钮 /// </summary> public GameObject onClockButton; public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera) { Vector2 localPoint; Debug.Log(screenPoint); RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("Canvas").GetComponent<RectTransform>(),screenPoint, eventCamera, out localPoint); if (onClockButton.GetComponent<RectTransform>().rect.Contains(localPoint)) { return false; } else { return true; } } }
代码挂载到要被穿透的UI上
使用遮罩为
关掉遮罩的点击事件响应