- Home /
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! James.
Answer by Catlard · Dec 18, 2012 at 10:59 AM
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.
S
Answer by Zarenityx · Jan 09, 2013 at 03:03 AM
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).
Your answer
![](https://koobas.hobune.stream/wayback/20220613085610im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
right mouse down on a gameObject 2 Answers
Click and Drag Camera 3 Answers
Draggable Doors Like Amnesia? 1 Answer
click vs long press (drag) help? 1 Answer
Click but not drag 1 Answer