Legacy Documentation: Version 5.4
LanguageEnglish
  • C#
  • JS

Script language

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

Cursor.SetCursor(Texture2D,CursorMode)

Description

Change the mouse cursor to the set texture OnMouseEnter.

Reset the cursor to default OnMouseExit.

using UnityEngine;
using System.Collections;

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() { Cursor.SetCursor(null, Vector2.zero, cursorMode); } }

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

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.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961