Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- [ExecuteInEditMode]
- public class UIColliderMask : MonoBehaviour, ICanvasRaycastFilter
- {
- private RectTransform _rectTransform = null;
- public RectTransform rectTransform
- {
- get
- {
- #if UNITY_EDITOR
- if(!UnityEditor.EditorApplication.isPlaying)
- return GetComponent<RectTransform>();
- #endif
- return _rectTransform ?? (_rectTransform = GetComponent<RectTransform>());
- }
- }
- void Update()
- {
- float s = rectTransform.rect.width * colliderAspect;
- colliderGameObject.transform.localScale = new Vector3 (s, s, s);
- }
- public GameObject colliderGameObject = null;
- public float colliderAspect = 0.0f;
- public bool IsRaycastLocationValid(Vector2 screenPosition, Camera raycastEventCamera)
- {
- return colliderGameObject.collider2D.OverlapPoint (screenPosition);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement