Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

Cursor.SetCursor

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static void SetCursor(Texture2D texture, Vector2 hotspot, CursorMode cursorMode);

Parameters

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.

Description

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); } }