x


change mouse cursor on mouseover

How can I change the mouse cursor when the mouse is over a certain object in the scene? I'd really appreciate the help.

more ▼

asked Jan 10 '11 at 01:19 PM

nom-t gravatar image

nom-t
1 2 2 4

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

4 answers: sort voted first

You would need to do a raycast between the observer (your PoV) and mouse and detect if that line collides with the object. Now that you caught the event you will have to go into the mouse properties and change the settings there.

This is not the easiest thing to do, do not misunderstand, it is most certainly possible. But I have no idea of 1: what your objective is. So I can not give much alternatives. I am not sure you are able to use this solution at all, so I will not spend a huge amount of time coding some sample which could just be ending up as useless.

So I would request specifying your question, or simply use the first suggestion or that of any other answer that pops up here :)

more ▼

answered Jan 10 '11 at 03:01 PM

Proclyon gravatar image

Proclyon
1.4k 11 13 32

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

like this:

var myCursor:Texture2D;
var cursorSizeX: int = 32;  // set to width of your cursor texture
var cursorSizeY: int = 32;  // set to height of your cursor texture
var condition = true;

function OnMouseEnter(){
    condition = false;
    Screen.showCursor = false;
}

function OnMouseExit(){
    condition = true;
    Screen.showCursor = true;
}

function OnGUI(){
    if(!condition){
       GUI.DrawTexture (Rect(Input.mousePosition.x-cursorSizeX/2 + cursorSizeX/2, (Screen.height-Input.mousePosition.y)-cursorSizeY/2 + cursorSizeY/2, cursorSizeX, cursorSizeY),myCursor);
    }
}

bye!

more ▼

answered Jan 04 '12 at 02:11 PM

lcn75 gravatar image

lcn75
136 6 6 8

one problem with this is it will work fine with only one object, whn number of objects increases it will fail

Jan 06 '12 at 06:31 AM flamy
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Jan 05 '12 at 10:06 AM

lcn75 gravatar image

lcn75
136 6 6 8

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

Nice, but i dont want change texture scale.

more ▼

answered Oct 17 '12 at 12:04 PM

xsound gravatar image

xsound
0 1 2 2

Is this an answer for this post? Please moderators when you see an answer like this please delete them, I wish I had the right to do so.

Jun 10 '13 at 09:26 PM moghes
(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:

x1314
x283
x55
x17

asked: Jan 10 '11 at 01:19 PM

Seen: 12344 times

Last Updated: Jun 10 '13 at 09:27 PM