Sorry for the simplistic title, but I’m working on creating draggable UI elements but for some reason it seems like the OnMouseDrag function is simply not working. Here’s what I have:
var btn : Texture;
function OnGUI () {
if(GUI.Button(Rect(10, 10, btn.width, btn.height), btn, "label"))
Debug.Log("Button Pressed");
}
function OnMouseDrag() {
Debug.Log("Dragging.");
}
The call to Debug.Log in the OnMouseDrag function never fires when clicking within the texture button and dragging.
OnGUI and OnMouseDrag are not directly related. OnGUI is the entry point for the ‘Unity GUI 2.0’ system. OnMouseDrag is a MonoBehavior event that triggers when the mouse is over a GUIElement or Collider.
So either implement the button with a GUIElement and OnMouseDown(), or use OnGUI() and check out the EventType.