- Home /
Creating a custom cursor.
How do I create a custom cursor? When I set my cursor image in the player settings it just gives me a gray box as the cursor.
Answer by Eric5h5 · Dec 16, 2012 at 05:43 AM
Try setting the texture type to Cursor, and limiting the size to 32x32. I found that while setting the cursor in the player settings worked in the editor, it did not show up in a build. I worked around that by using Cursor.SetCursor in a script instead.
+1 for explaining HW Cursors, I always appreciate fair mannered explanations. :)
I did that, but still dont know what parameter put on Cursor.SetCursor(). Any help? Thanks
There is an even easier way. Click on your custom cursor's texture to see it's settings in the Inspector, then click on "Texture Type" and click "Cursor". Now it works!
Answer by clunk47 · Oct 07, 2013 at 05:58 PM
You could also use GUI.DrawTexture like so:
var mouse : Vector2;
var w : int = 32;
var h : int = 32;
var cursor : Texture2D;
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 - (w / 2), mouse.y - (h / 2), w, h), cursor);
}
Wow...@clunk47 Thanks very much ! It worked for me. =)
This is helpful. Adds more flexibility to cursor size. I never knew Screen and GUI existed. Screen.showCursor is deprecated now to UnityEngine.Cursor.visible, but other than that, I like this answer. Thanks!
@clunk47 The script does work in adding the cursor into the environment. It does follow the mouse, sort of. It never seems to be fully in synch to where the mouse is. It seems to be offset slightly. How do I fix this?
$$anonymous$$aybe you need to modify the hotspot of the cursor (offset of click location from top left corner of the cursor image). Check this (old) Unity blog entry for more info about custom cursors.
Your answer
Follow this Question
Related Questions
Cursor Lockmode only works once? 1 Answer
Cursor bug 0 Answers
Keep Cursor at center and project interactions to cursor position on mobile touch devices (IOS) 0 Answers
Cursor.lockState does not work 2 Answers