Hi guys i’ve got a question: how can i change cursor’s texture when the cursor is over specific gameobject?
still nothing…?
Ok, solution found
var cursor : Texture2D;
var link : Texture2D;
var normal : Texture2D;
/*On mouse over hide the cursor and show the "link" cursor.*/
function Update (){
Screen.showCursor = false;
}
function OnMouseOver () {
Screen.showCursor = false;
cursor = link;
}
/*On mouse exit reset to the "normal" cursor. You can leave the "normal" variable blank or populate with any texture.*/
function OnMouseExit () {
Screen.showCursor = false;
cursor = normal;
}
/*Make the "link" texture follow the cursor.*/
function OnGUI () {
GUI.Label(Rect(Input.mousePosition.x-12, Screen.height - Input.mousePosition.y-10, 100, 100), cursor);
}
Just assigned this script to the “specific gameobject”
Now another question how to change cursor texture when the mouse button is pressed, and change back when the mouse button is released?
You can use the Screen.showCursor flag to hide the cursor and then draw a texture at the mouse position, say with GUI.DrawTexture. Since you will be drawing the texture directly, you can switch it for another when you detect the mouse button is down.
You’ve almost got it. You’re using OnMouseOver, OnMouseExit. Try using OnMouseDown, and OnMouseUp to set the texture.
Thanx for help i appreciate that.
But i’ve got my LAST question to U:
So this is a script to change the texture of the cursor when it is over the object:
var cursor : Texture2D;
var link : Texture2D;
var normal : Texture2D;
function OnMouseOver () {
Screen.showCursor = false;
cursor = link;
}
function OnMouseExit () {
Screen.showCursor = false;
cursor = normal;
}
function OnGUI () {
GUI.Label(Rect(Input.mousePosition.x-12, Screen.height - Input.mousePosition.y-10, 100, 100), cursor);
}
It works perfectly in case when there is only one object, with this script assigned, at a scene, but when there are more than 1 object, when you put your cursor over the object cursor’s textures “cursor” and “link” are displayed simultaneously. How can i fix it any clues?
still digging it…
hey guys, this script isnt working for me
ive used this one
Thank you very much i was looking to do it, and i didn´t realised about Screen.height - Input.mousePosition.y. Great!
@hellcaller : GUI.Label(Rect(Input.mousePosition.x-12, Screen.height-Input.mousePosition.y-10, 100, 100), cursor); Pls change this script to c#…