BagButtonChangeUI.cs 1020 B

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