Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

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

Cursor.SetCursor(Texture2D,CursorMode)

Switch to Manual

Description

Change the mouse cursor to the set texture OnMouseEnter.

Reset the cursor to default OnMouseExit.

#pragma strict
public var cursorTexture: Texture2D;
public var cursorMode: CursorMode = CursorMode.Auto;
public 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;

Parameters

texture The texture to use for the cursor or null to set the default cursor. Note that a texture needs to be imported with "Read/Write enabled" in the texture importer (or using the "Cursor" defaults), in order to be used as a 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.