mirror of
https://github.com/tym1116/BH3.git
synced 2025-12-13 15:04:35 +01:00
23 lines
620 B
C#
23 lines
620 B
C#
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(RectTransform), typeof(Collider2D))]
|
|
public class RaycastMask : MonoBehaviour, ICanvasRaycastFilter
|
|
{
|
|
private Collider2D myCollider;
|
|
|
|
private RectTransform rectTransform;
|
|
|
|
private void Awake()
|
|
{
|
|
myCollider = GetComponent<Collider2D>();
|
|
rectTransform = GetComponent<RectTransform>();
|
|
}
|
|
|
|
public bool IsRaycastLocationValid(Vector2 screenPos, Camera eventCamera)
|
|
{
|
|
Vector3 worldPoint = Vector3.zero;
|
|
RectTransformUtility.ScreenPointToWorldPointInRectangle(rectTransform, screenPos, eventCamera, out worldPoint);
|
|
return myCollider.OverlapPoint(worldPoint);
|
|
}
|
|
}
|