Skip to content

Instantly share code, notes, and snippets.

@TxN
Created December 5, 2019 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TxN/344c216ecd31cca5850ea7294fd5f0a6 to your computer and use it in GitHub Desktop.
Save TxN/344c216ecd31cca5850ea7294fd5f0a6 to your computer and use it in GitHub Desktop.
[RequireComponent(typeof(Collider2D))]
public sealed class ColliderRaycastFilter : MonoBehaviour, ICanvasRaycastFilter {
Collider2D _collider;
void Start() {
_collider = GetComponent<Collider2D>();
}
public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera) {
return _collider && _collider.OverlapPoint(eventCamera.ScreenToWorldPoint(sp));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment