SampleCubeCtrl.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7. public class SampleCubeCtrl : MonoBehaviour, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
  8. {
  9. private bool m_update = false;
  10. private bool m_rotDirection = false;
  11. //public void OnPointerEnter()
  12. //{
  13. // //Debug.Log("[MercuryX2] Cube:OnPointerEnter");
  14. //}
  15. //public void OnPointerExit()
  16. //{
  17. // m_update = false;
  18. // Debug.Log("[MercuryX2] Cube:OnPointerExit");
  19. //}
  20. //public void OnPointerClick()
  21. //{
  22. // Debug.Log("[MercuryX2] Cube:OnPointerClick");
  23. //}
  24. private void Update()
  25. {
  26. if (!m_update)
  27. {
  28. transform.Rotate(Vector3.forward * (m_rotDirection ? 1 : -1)*0.1f, Space.World);
  29. return;
  30. }
  31. transform.Rotate(Vector3.forward * (m_rotDirection ? 1 : -1), Space.World);
  32. }
  33. public void OnPointerEnter(PointerEventData eventData)
  34. {
  35. m_update = true;
  36. }
  37. public void OnPointerExit(PointerEventData eventData)
  38. {
  39. m_update = false;
  40. }
  41. public void OnPointerClick(PointerEventData eventData)
  42. {
  43. m_rotDirection = !m_rotDirection;
  44. }
  45. }