How can I make GUI labels Draggable?

Hi Guys, Quick Question, I have a label on a map view of my scene, how do i make it clickable and draggable?

GUI.Label(new Rect((goTransform.position.x*(0.23f) - (800)(0.23f) +5)(-1),(goTransform.position.z*(0.23f) + (600)*(0.23f) -5),10,10),“”,guiSkin.customStyles[1]);

Thanks in advance!

Hey, James. Here’s my idea:

Your label’s position should be determined by a Rect object, whose .x and .y properties you modify whenever someone has clicked and continues to hold down the mouse button. You just make the values of that rect’s .x and .y properties equal to whatever Input.MousePosition is at the time that the mouse is being held down, and the person originally started by clicking within the range of that GUI.Label. I don’t have any code, but that’s how it would work, if I did it.


Catlard described the basics, but if you wanted to practically do this, you will probably style a repeatbutton to look like a label, then check when the mouse is down. If the mouse is down, and the repeatbutton is returning true( it is being clicked on) the first two elements of the rect can be set to the mouse coordinates. This also has the advantage of making it more visible that the player is dragging that object, because you can style the clicked version too so that it looks a bit different from the unclicked version (glows or something).