| Parameter | Description |
|---|---|
| texture | The texture to use for the cursor. To use a texture, import it with `Read/Write` enabled. Alternatively, you can use the default cursor import setting. If you created your cursor texture from code, it must be in RGBA32 format, have alphaIsTransparency enabled, and have no mip chain. To use the default cursor, set the texture to `Null`. |
| hotspot | The offset in pixels from the top-left of the texture to the cursor's target. The x-axis increases to the right and the y-axis increases downward. This must be within the texture bounds. |
| cursorMode | Whether to render this cursor as a hardware cursor on supported platforms, or force software cursor. |
Sets a custom cursor to use as your cursor.
Call Cursor.SetCursor with a Texture2D to change the appearance of the hardware pointer (mouse cursor).
In the Unity Editor, the custom cursor applies to the Game view during Play mode. It doesn't replace the Editor cursor over Editor windows such as the Inspector window or Scene view.
using UnityEngine;
// Attach this script to a GameObject with a Collider, then mouse over the object to see your cursor change. public class ExampleClass : MonoBehaviour { public Texture2D cursorTexture; public CursorMode cursorMode = CursorMode.Auto; public Vector2 hotSpot = Vector2.zero;
void OnMouseEnter() { Cursor.SetCursor(cursorTexture, hotSpot, cursorMode); }
void OnMouseExit() { // Pass 'null' to the texture parameter to use the default system cursor. Cursor.SetCursor(null, Vector2.zero, cursorMode); } }