Clickable.cs 668 B

123456789101112131415161718192021222324252627282930313233343536
  1. using UnityEngine;
  2. public class Clickable : MonoBehaviour
  3. {
  4. public delegate void ClickAction();
  5. public event ClickAction OnClicked;
  6. [HideInInspector]
  7. public bool Interactable = true;
  8. private bool once;
  9. virtual public void DoSomething()
  10. {
  11. FadeScreen.Instance.active = false; // interrupt update fading if user want to fast change location
  12. if (OnClicked != null)
  13. {
  14. OnClicked();
  15. }
  16. }
  17. private void OnMouseDown()
  18. {
  19. if (!once && Interactable)
  20. {
  21. DoSomething();
  22. once = true;
  23. }
  24. }
  25. private void OnMouseUp()
  26. {
  27. once = false;
  28. }
  29. }