GUI Drag and Drop

I'd like to drag a texture from one GUI.Box to another GUI.Box. My initial thought is I can attach the texture to the mouse cursor using if(GUI.Box...) but I don't think that is the same as OnMouseDown. Past that, I'm not really sure how to make use of OnMouseDrag/OnMouseUp type functions in the GUI. Thanks.

You'll need to make extensive use of the Event class

Some things which will help:

Event.current.type will give you the EventType, which you will need to check for EventType.MouseDrag, EventType.MouseUp and EventType.MouseDown

Event.current.mousePosition you will need to find the current mouse position in gui space, relative to the current GUI.Group.

yourBoxRect.Contains(Event.current.mousePosition) will return true if your mouse cursor is inside the defined rect, also in GUI space, relative to the current group (so will always match with your box rect if you call it right before/after)

Besides that, just register if you mouse down inside the first box, then draw a texture during the drag event, and finally check if you mouse up on the second box

I don't know how, neither if, you can do it with OnMouse functions, but I can tell you how I Did it. Take look at this code

var firstBoxTexture : Texture2D; var secondBoxTexture : Texture2D; var currentTexture : Texture2D;

if( GUI.Box( rect, firstBoxTexture ) )
   // Drag
   if( firstBoxTexture != null )
      currentTexture = firstBoxTexture;
      firstBoxTexture = null;
   // Drop
      firstBoxTexture = currentTexture ;
      currentTexture = null;
// Same thing for the other one, with secondBoxTexture

If you get the idea, it should work