x


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?

more ▼

asked Jul 18 '11 at 12:02 AM

ZeKurt gravatar image

ZeKurt
1 6 7 9

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

Jul 18 '11 at 12:23 AM SilverTabby

@SilverTabby: Use Event.current.mousePosition in OnGUI, not Input.mousePosition. Otherwise you get screen coords instead of GUI coords.

Jul 18 '11 at 12:25 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);
}
more ▼

answered Jul 18 '11 at 04:28 AM

YikYikHeiHei gravatar image

YikYikHeiHei
311 8 9 13

As I said, don't use Input.mousePosition in OnGUI, use Event.current.mousePosition. Then you don't have to convert coords.

Jul 18 '11 at 04:59 AM Eric5h5

Thank you!

Jul 18 '11 at 11:34 AM ZeKurt

Or you could use the framework: http://edrivenunity.com/cursors

Jul 11 '12 at 04:33 PM dkozar
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3738
x199
x198

asked: Jul 18 '11 at 12:02 AM

Seen: 3799 times

Last Updated: Jul 11 '12 at 04:33 PM