- Home /
UNITY3D: Custom cursors?
Hi, I'm developing my main menu for my game and I want a custom cursor for this. Is there anyway I could do that?
This might be a bit ghetto, but I would just use GUI.DrawTexture() at Input.mousePosition and pass your cursor image into GUI.DrawTexture().
Simple but effective.
http://unity3d.com/support/documentation/ScriptReference/GUI.DrawTexture.html
http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html
@SilverTabby: Use Event.current.mousePosition in OnGUI, not Input.mousePosition. Otherwise you get screen coords ins$$anonymous$$d of GUI coords.
Answer by YikYikHeiHei · Jul 18, 2011 at 04:28 AM
Here a script ---
And now is use Event.current.mousePosition---
var yourCursor : Texture2D; // Your cursor texture
var cursorSizeX : int = 16; // Your cursor size x
var cursorSizeY : int = 16; // Your cursor size y
function Start()
{
Screen.showCursor = false;
}
function OnGUI()
{
GUI.DrawTexture (Rect(Event.current.mousePosition.x-cursorSizeX/2, Event.current.mousePosition.y-cursorSizeY/2, cursorSizeX, cursorSizeY), yourCursor);
}
As I said, don't use Input.mousePosition in OnGUI, use Event.current.mousePosition. Then you don't have to convert coords.
Or you could use the framework: http://edrivenunity.com/cursors
Answer by tsmitro · Jun 11, 2013 at 01:55 PM
Unity provides built-in support for custom cursors under the Player Settings. I don't know if this was supported in whatever version of Unity was around during the first post, but I figured I'd put this up for those of you still looking.
Thanks for adding this, future answers can be even more helpful.
But you would be able to do more with other methods, but unity's built in method is -probably- bug free. lol
Answer by RKSandswept · Oct 03, 2013 at 08:17 AM
I also found that the image used for the cursor must be set to cursor, and also point scaling (not bi-linear nor tri-linear). If it is not set to point I always got a 50% opaque purplish square instead.