x


GUI cursor position off

Hi, I'm overlaying a GUI texture to the position of the mouse. However, the actual click point, the end of the cursor, is off by a little to the left and up of my actual texture. How do I fix this?

Here's my script:

function Start() {
    Screen.showCursor = false;
}

function OnGUI() {
    var mousePos : Vector3 = Input.mousePosition;
    var pos : Rect = Rect(mousePos.x,Screen.height - mousePos.y,cursorImage.width,cursorImage.height);
    GUI.Label(pos,cursorImage);
}
more ▼

asked Aug 02 '10 at 08:47 PM

e.bonneville gravatar image

e.bonneville
5.7k 100 116 165

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You need to offset the rect by half the width and height:

var pos : Rect = Rect(mousePos.x - cursorImage.width / 2.0, Screen.height - mousePos.y - cursorImage.height / 2.0, cursorImage.width, cursorImage.height);

more ▼

answered Aug 02 '10 at 09:20 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

Right, thanks. Accepted

Aug 02 '10 at 09:37 PM e.bonneville
(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:

x3695
x198

asked: Aug 02 '10 at 08:47 PM

Seen: 1459 times

Last Updated: Aug 02 '10 at 08:47 PM