MouseButton.cs 787 B

1234567891011121314151617181920212223242526272829
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class MouseButton : MonoBehaviour
  6. {
  7. [SerializeField] RectTransform targetRTF;
  8. [SerializeField] Graphic targetGraphic;
  9. [SerializeField] Color selectedColor = new Color(1, 1, 1, 0.6f);
  10. Vector3 _scale;
  11. Color _color;
  12. public void OnSelect() {
  13. if (targetGraphic) {
  14. _color = targetGraphic.color;
  15. targetGraphic.color = selectedColor;
  16. }
  17. if (targetRTF) {
  18. _scale = targetRTF.localScale;
  19. targetRTF.localScale = _scale * 1.15f;
  20. }
  21. }
  22. public void OnExit() {
  23. if (targetGraphic) targetGraphic.color = _color;
  24. if (targetRTF) targetRTF.localScale = _scale;
  25. }
  26. }