GuideButtonChangeUI.cs 980 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using TMPro;
  2. using UnityEngine.EventSystems;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class GuideButtonChangeUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
  6. {
  7. public Image guideButtonBG;
  8. public Image guideIcon;
  9. public TextMeshProUGUI txt;
  10. public Sprite targetBG;
  11. public Sprite targetIcon;
  12. private Sprite curBG;
  13. private Sprite curIcon;
  14. private void Awake()
  15. {
  16. curBG = guideButtonBG.sprite;
  17. curIcon = guideIcon.sprite;
  18. }
  19. public void OnPointerEnter(PointerEventData eventData)
  20. {
  21. ChangeUI();
  22. }
  23. public void OnPointerExit(PointerEventData eventData)
  24. {
  25. ResetUI();
  26. }
  27. public void ChangeUI()
  28. {
  29. guideButtonBG.sprite = targetBG;
  30. guideIcon.sprite = targetIcon;
  31. txt.color = Color.black;
  32. }
  33. public void ResetUI()
  34. {
  35. guideButtonBG.sprite = curBG;
  36. guideIcon.sprite = curIcon;
  37. txt.color = Color.white;
  38. }
  39. }