NG_/Assets/Scripts/UI/全局/CursorChanger.cs

26 lines
774 B
C#
Raw Permalink Normal View History

2025-01-10 16:52:52 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
// 鼠标移入UI时光标改变
public class CursorChanger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public Texture2D handCursor; // 用于存放小手光标图标
public Vector2 hotSpot = new Vector2(0, 0); // 设置光标热点
// 鼠标移入时调用
public void OnPointerEnter(PointerEventData eventData)
{
// 设置光标为小手图标
Cursor.SetCursor(handCursor, hotSpot, CursorMode.Auto);
}
// 鼠标移出时调用
public void OnPointerExit(PointerEventData eventData)
{
// 恢复为默认光标
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
}