0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Unity]マウスカーソルのサイズ変更 C# Windows実行環境

Last updated at Posted at 2020-07-03

最初に

 ・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にアタッチします。

なんやかんやセット
無題.png

結果

Dキーをプッシュ
無題.png

※何度も変更していると画像がぼやけるのでソースを修正。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?