- Home /
change the cursor texture when clicked oon the gui button!!
hello ,
I am working on a gui iterface in unity where when user click on the Button the Cursor should be changed to any texture..or the sprite should come up near the cursor(same as processing cursor when the system is processing something..round processor that shows that the system is processing)
Comment
Answer by Hims · Jul 18, 2012 at 06:50 AM
I got the solution by my self.. it is as below...it attaches a sprite(texture) that follows the mouse pointer when clicked on the button.
var cursor : Texture2D;
var link : Texture2D;
var normal : Texture2D;
function Start()
{Screen.showCursor = false;
}
function Update (){
Screen.showCursor = true;
}
function OnGUI () {
if(GUI.Button (Rect (10,10,100,20), GUIContent ("Button 1", "Button 1"))){
/*Hide the cursor and show the "link" cursor.*/
Screen.showCursor = false;
cursor = link;
}
if(GUI.Button (Rect (110,10,100,20), GUIContent("Button 2", "Button 2"))){
/* Reset to the "normal" cursor. You can leave the "normal" variable blank or populate with any texture.*/
Screen.showCursor = false;
cursor = normal;
}
/*Make the "link" texture follow the cursor.*/
GUI.Label(Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y-12, 32, 32), cursor);
// GUI.Label(Rect(Input.mousePosition.x-12, Screen.height - Input.mousePosition.y-10, 100, 100), normal);
//GUI.DrawTexture(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, cursorWidth, cursorHeight), cursor);
}