- Home /
Drag and Drop
hi! i have an inventory in my game but didn't drag and drop. how to use the drop and drag? if i have selected a button, the button must be clear and the objects must be drag and drop?
Answer by tcmwaffles · Apr 30, 2012 at 12:48 AM
Angry Ant has a pretty good example on how to do this. Basically create your own GUI Draggable object and then flesh out the details as needed. http://angryant.com/2009/09/18/gui-drag-drop/
Answer by roamcel · Aug 22, 2011 at 12:31 PM
I'm not completely sure of what you need, but I guess you can start from here:
http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseDrag.html
Of course it only applies to guielements and colliders, as stated.
I think he talks about drag and drop inventories, like in the RPG's and $$anonymous$$$$anonymous$$O's
Answer by thienhaflash · Jun 16, 2012 at 09:25 AM
Although the answer on AngryAnt's site is very complete, it's not very easy to apply if you don't understand the things deeply. Based on that, I rolled my own solution, to make a GUI object draggable, just add the following code :
DragBox db = DragBox.Get("Button1_db", false);
if (db != null){//if that DragBox is already created, render using the rect
GUI.Button(db.rect, "Button1");
} else {//not yet exist
GUILayout.Button("Button1", GUILayout.Width(100));
DragBox.Get("Button1_db", true); //try to create a new DragBox
}
the class DragBox can be download here : https://dl.dropbox.com/u/10796188/wp/unity/DragBox.cs
Sorry for interrupting. I am using your DragBox class and it works nice. my question is how to replace Button1_db with textured object, for example:
private Texture green; GUI.DrawTexture(new Rect(60,10,50,50),green);
how to move this green object?
Answer by Aarlangdi · Mar 07, 2014 at 03:19 PM
Check this out this might help you guys -- http://unityshorttutorials.blogspot.com.au