공부/Unity

[Unity] 버튼에 마우스 오버시 이미지 바꾸기 UI

굴러다니다니 2023. 10. 12. 09:45
728x90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

public class MouseOverBtn : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    [SerializeField] private GameObject originalBtn;
    [SerializeField] private Sprite originalSprite;
    [SerializeField] private Sprite colorChangeSprite;
    
    public void OnPointerEnter(PointerEventData eventData)
    {
        originalBtn.GetComponent<Image>().sprite = colorChangeSprite;
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        originalBtn.GetComponent<Image>().sprite = originalSprite;
    }
}
728x90