将鼠标光标设置为给定纹理。
使用 Texture2D 调用此方法以更改硬件指针(鼠标光标)的外观。cursorMode
参数允许您在支持的平台上使用硬件光标,或者强制软件渲染光标。
在以下示例中,鼠标光标将在调用 OnMouseEnter 时更改为给定纹理,并在调用 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); } }
texture | The texture to use for the cursor. To use a texture, you must first 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 | 要用作目标点的从左上角开始的纹理偏移(必须在光标边界内)。 |
cursorMode | 允许此光标在支持的平台上渲染为硬件光标,或者强制使用软件光标。 |
指定要用作光标的自定义光标。
使用 Texture2D 调用此方法以更改硬件指针(鼠标光标)的外观。