- Home /
Cursor size with SetCursor or alternative?
I've been working with my own cursor in unity and it works beautifully except for one small issue, no pun intended. My custom cursor is TINY. I have made sure to set up the proper import settings on the texture and I have the max size set to 256 just to be safe. The image size is 63x63px and I've even resized it to 100x100px as a test, yet the cursor is stell VERY tiny in game.
I have found one solution using OnGUI() and DrawTexture using the mouse's position for the Rect. But that doesn't seem to work for me, as the texture does not show up for some reason.
Are there any other alternatives to re-sizing the cursor size so I can continue using SetCursor, it's so much cleaner. The file type for the cursor texture is .bmp, not sure if that may be causing conflicts or not.
Answer by BBrown4 · Aug 28, 2014 at 07:29 AM
I always answer my own darn questions. I apologize for having wasted anyone's time. Here is a tip for everyone out there who I know is not as dumb as I am. It might be a good idea to make sure the script component is actually turned on while trying to get something to work -__- I feel like an idiot haha. For anyone who comes along with this same issue, for now the solution that worked for me is the OnGUI() methid shown below:
public Texture2D cursorTex;
public int cursorSize = 63;
int sizeX;
int sizeY;
void Awake() {
sizeX = cursorSize;
sizeY = cursorSize;
}
void Start()
{
Screen.showCursor = false;
}
void Update() {
sizeX = cursorSize;
sizeY = cursorSize;
}
void OnGUI()
{
GUI.DrawTexture(new Rect(Event.current.mousePosition.x - (cursorSize/2), Event.current.mousePosition.y - (cursorSize/2), sizeX, sizeY), cursorTex);
}
clearly the cursorSize would be your own size. I set it up the way I did because my crosshair/cursor will always have the same y size as the x size and doing it with the variables I did allows you to scale your cursor size directly from within the inspector with a single variable, however depending on your particular situation you may want to modify that in your own way.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do I keep a Custom Cursor (GUITexture) on top of UnityGUI controls? 3 Answers
Toggle Only Works Once 1 Answer
Best way to change alpha on per object basis. (c#) 0 Answers