Search code examples
c#unity-game-engine

How to get the mouse cursor default texture in unity3d?


private Texture2D defaultCursor; // Store the original cursor

void Start()
{
    Cursor.SetCursor(defaultCursor, Vector2.zero, CursorMode.Auto); // Store the default cursor
}

doing it like this the defaultCursor variable will be null and therefore i will not be able to use it later in the code.

i want that when i use somewhere in my code with Cursor.SetCursor with my custom texture image that i will be able to change it back to the default mouse cursor texture when need.

I saw that there is a MouseCursor and you can do for example MouseCursor.Pan or MouseCursor.Arrow but how can i change the mousecursor shape to this Pan or Arrow ? without custom texture.


Solution

  • To set the mouse to the default mouse texture call Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto), which sets the sprite to null showing the default cursor.