Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Cursor.SetCursor(Texture2D,CursorMode)

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

Sumbission failed

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

Close

Cancel

Description

Change the mouse cursor to the set texture OnMouseEnter.

Reset the cursor to default OnMouseExit.

	var cursorTexture : Texture2D;
	var cursorMode : CursorMode = CursorMode.Auto;
	var hotSpot : Vector2 = Vector2.zero;

function OnMouseEnter () { Cursor.SetCursor(cursorTexture, hotSpot, cursorMode); }

function OnMouseExit () { Cursor.SetCursor(null, Vector2.zero, cursorMode); }
public static function SetCursor(texture: Texture2D, hotspot: Vector2, cursorMode: CursorMode): void;
public static void SetCursor(Texture2D texture, Vector2 hotspot, CursorMode cursorMode);
public static def SetCursor(texture as Texture2D, hotspot as Vector2, cursorMode as CursorMode) as void

Parameters

texture The texture to use for the cursor.
hotspot The offset from the top left of the texture to use as the target point (must be within the bounds of the cursor).
cursorMode Allow this cursor to render as a hardware cursor on supported platforms, or force software cursor.

Description

Specify a custom cursor that you wish to use as a cursor.