TIL
[Unity] Valley - Mouse Cursor 변경하기
habbn
2024. 11. 24. 03:49
728x90
마우스 커서를 변경하기 위해서 마우스 Sprite의 Texture Type을 Cursor로 변경해줘야 한다.
그리고 SetCursor를 사용하여 내가 설정한 새로운 커서 텍스쳐 이미지로 커서를 변경한다.
using UnityEngine;
public class ChangeCursor : MonoBehaviour
{
public static ChangeCursor instance;
public Texture2D newCursorTexture;
void Awake()
{
if (!instance)
{
instance = this;
DontDestroyOnLoad(this.gameObject);
}
else
{
Destroy(gameObject);
}
}
void Start()
{
Cursor.SetCursor(newCursorTexture, Vector2.zero, CursorMode.Auto);
}
void OnDisable()
{
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
}
}
그리고 새로운 게임오브젝트를 생성하여 ChangeCursor 스크립트와 마우스 스프라이트를 추가한다.
그러면 이렇게 새로 지정한 스프라이트로 커서가 변경된다.
728x90