| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.Events; |
| | 3 | |
|
| | 4 | | [RequireComponent(typeof(RectTransform))] |
| | 5 | | public class CallbackOnExternalClick : MonoBehaviour |
| | 6 | | { |
| | 7 | | public UnityEvent callback; |
| | 8 | |
|
| | 9 | | private RectTransform rectTransform; |
| | 10 | |
|
| 0 | 11 | | private void Awake() { rectTransform = GetComponent<RectTransform>(); } |
| | 12 | |
|
| | 13 | | // Update is called once per frame |
| | 14 | | void Update() |
| | 15 | | { |
| 0 | 16 | | if (Input.GetMouseButtonDown(0)) |
| | 17 | | { |
| 0 | 18 | | if (!RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition)) |
| | 19 | | { |
| 0 | 20 | | callback.Invoke(); |
| | 21 | | } |
| | 22 | | } |
| 0 | 23 | | } |
| | 24 | | } |