最初に
・Unityのバージョンは[2019.4.0f1]です!
・Windows環境のみです。
やってること
・画像を縮小拡大してマウスカーソルにあげるだけです。
スクリプト
GameSetting.cs
using UnityEngine;
using UnityEngine.AddressableAssets;
public class CursorManager : MonoBehaviour {
public Texture2D sprite;
public CursorMode cursorMode = CursorMode.ForceSoftware;
public Vector2 hotSpot = Vector2.zero;
public int size;
private void Update() {
if(Input.GetKeyDown(KeyCode.D)) {
Cursor.SetCursor(ResizeTexture(sprite,size,size)), hotSpot, cursorMode);
}
}
static Texture2D ResizeTexture(Texture2D srcTexture, int newWidth, int newHeight) {
var resizedTexture = new Texture2D(newWidth, newHeight, TextureFormat.RGBA32, false);
Graphics.ConvertTexture(srcTexture, resizedTexture);
return resizedTexture;
}
}
(使い方)上記のスクリプトを適当な汎用Objにアタッチします。
結果
※何度も変更していると画像がぼやけるのでソースを修正。