- Home /
How do I make my cursor smaller?
I'm creating a menu for a game and want to change the cursor to a hand when the mouse hovers over buttons. I'm using Cursor.SetCursor()
The problem is that, when I'm using CursorMode.Auto, the cursor its rendered way bigger than the default cursor. When I use CursorMode.ForceSoftware, its rendered nicely but its rendered to the left of where Im pointing.This is the code I use, which is attached to the camera object
public Texture2D handCursor;
public void hoverHand(){
Cursor.SetCursor (handCursor, Vector2.zero, CursorMode.Auto);
}
public void returnCursor(){
Cursor.SetCursor (null, Vector2.zero, CursorMode.Auto);
}
I'm using Event trigger on the buttons. On pointer enter it calls hoverHand(), on pointer exit it calls returnCursor()
This is the image I'm using. It's 17 X 22
Hope you guys can help me! Have a nice day.
Answer by nullgobz · Jul 31, 2015 at 12:06 AM
The Cursor.SetCursor will auto resize your cursor to 32x32 if its smaller when using CursorMode.Auto. And i would not recommend using software rendering.
What you could do if you really wanted a smaller cursor is make your own. Example: Texture2D Cursor; int Width = 16, Heigth = 16; Vector2 mouse;
function Start()
{
Screen.showCursor = false;
}
function Update()
{
mouse = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
}
function OnGUI()
{
GUI.DrawTexture(new Rect(mouse.x - (Width / 2), mouse.y - (Heigth / 2), Width, Heigth), Cursor);
}
Yeh im aware that OnGUI is the legacy system. You could do it with the uGUI if you prefer.
Answer by unity_x_qe4ZQcRm_jUg · Sep 06, 2020 at 05:01 PM
Yeah Blackthornprod's video in that topic should cover your question if you are still here in 2020... :) In his second technique he doesn't use a texture for the cursor, but he makes the cursor invisible and stick a sprite on top of it instead. That way, it is possible to create cursor animations, change the cursor sprite if right clicking, make particle effects and of course scale it to infinity. Here is the video: https://www.youtube.com/watch?v=cCKlMAwvQcI
Your answer
Follow this Question
Related Questions
Cursor Resize? 1 Answer
How Do I Lock the Cursor to the Center of the Screen? 1 Answer
How Can I Lock The Cursor Position? 1 Answer
How to prevent mouse lag/latency for custom cursor? 0 Answers
Cursor appears dark in game 0 Answers