【Uinity】关于鼠标指针的管理(以单例模式实现)

xiaoxiao2021-02-28  11

在游戏过程中,我们往往在面对不同的情景的时候会使用不同的鼠标图标,比如当鼠标放在npc上时鼠标的图标会变,实现这个其实很简单,只需将所有鼠标图标导入,通过以下方法即可实现。

using UnityEngine; using System.Collections; public class CursorManager : MonoBehaviour { public static CursorManager _instance; public Texture2D cursor_normal; public Texture2D cursor_npc_talk; public Texture2D cursor_attack; public Texture2D cursor_lockTarget; public Texture2D cursor_pick; private Vector2 hotspot = Vector2.zero; private CursorMode mode = CursorMode.Auto; void Start() { _instance = this; } public void SetNormal() { Cursor.SetCursor(cursor_normal, hotspot, mode); } public void SetNpcTalk() { Cursor.SetCursor(cursor_npc_talk, hotspot, mode); } public void SetAttack() { Cursor.SetCursor(cursor_attack, hotspot, mode); } public void SetLockTarget() { Cursor.SetCursor(cursor_lockTarget, hotspot, mode); } }

转载请注明原文地址: https://www.6miu.com/read-1100138.html

最新回复(0)