挂载在Button按钮上,继承IPointerEnterHandler和IPointerExitHandler接口,,实现移入和移出功能
using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class ZhiShiKuUIChange : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { private Image image; public Sprite[] sprites; void Start() { image = GetComponent<Image>(); } public void OnPointerEnter(PointerEventData eventData) { image.sprite = sprites[0]; } public void OnPointerExit(PointerEventData eventData) { image.sprite = sprites[1]; } }
接口复习: