Inventory Dragging slots

Hi ive recently created an inventory by following someones tutorial and im trying to figure out how to drag the item around i have a rough idea of how to do it
1 when you click on the item its contents is stored ina variable
2 it then removes itself from the slot
3 a gui follows the mouse
4 when you click on a new slot it adds the info to the slot

could anyone help me set this up?

using UnityEngine;
using System.Collections;

public class ItemClass : MonoBehaviour {

    //Icons
    public static Texture2D EmptyIcon;
    public static Texture2D CubeIcon ;
    public static Texture2D SphereIcon ;
    public static Texture2D CylinderIcon ;

    public Texture2D iEmptyIcon;
    public Texture2D iCubeIcon ;
    public Texture2D iSphereIcon ;
    public Texture2D iCylinderIcon ;

   

    //Items
    public ItemCreatorClass CubeItem = new ItemCreatorClass(0,"Cube",CubeIcon,"Description");
    public ItemCreatorClass SphereItem = new ItemCreatorClass(1,"Sphere",SphereIcon,"Description");
    public ItemCreatorClass CylinderItem = new ItemCreatorClass(2,"Cylinder",CylinderIcon,"Description");


    void Start()
    {
        EmptyIcon = iEmptyIcon;
        CubeIcon = iCubeIcon;
        SphereIcon = iSphereIcon;
        CylinderIcon = iCylinderIcon;
    }


    public class ItemCreatorClass
    {
        public int ItemID;
        public string ItemName;
        public Texture2D ItemIcon;
        public string ItemDescription;
       
        public ItemCreatorClass(int ID,string Name,Texture2D Icon,string Desc)
        {
            ItemID = ID;
            ItemName = Name;
            ItemIcon = Icon;
            ItemDescription = Desc;
        }
    }
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class InvGUI : MonoBehaviour {


    private bool InvToggle = false;
    private Rect InventoryWindow = new Rect(300,100,400,420);
   


    static public Dictionary<int,Texture2D> InventoryNameDictionary = new Dictionary<int,Texture2D> ()
    {
        {0, ItemClass.EmptyIcon},
        {1, ItemClass.EmptyIcon},
        {2, ItemClass.EmptyIcon},
        {3, ItemClass.EmptyIcon},
        {4, ItemClass.EmptyIcon},
        {5, ItemClass.EmptyIcon},
        {6, ItemClass.EmptyIcon},
        {7, ItemClass.EmptyIcon},
        {8, ItemClass.EmptyIcon},
    };

    static public List<int> dictionaryAmounts = new List<int>()
    {
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0

    };


    ItemClass itemObject = new ItemClass();
    // Update is called once per frame
    void Update ()
    {
        if (Input.GetKeyDown(KeyCode.I))
        {
            InvToggle = !InvToggle;
        }
    }


    void OnGUI()
    {
        if (InvToggle == true)
        {
            InventoryWindow = GUI.Window(0, InventoryWindow , InventoruWindowMethod,"Inventory");

        }

    }
                                       
    void InventoruWindowMethod (int Windowid = 0)
    {
        GUI.DragWindow(new Rect(0, 0, 10000, 20));
        GUILayout.BeginArea (new Rect (50, 30, 400, 400));

        //First Row
        GUILayout.BeginHorizontal ();
        GUILayout.Button (InventoryNameDictionary[0], GUILayout.Height (100), GUILayout.Width(100));
        GUILayout.Button (InventoryNameDictionary[1], GUILayout.Height (100), GUILayout.Width(100));
        GUILayout.Button (InventoryNameDictionary[2], GUILayout.Height (100), GUILayout.Width(100));
        GUILayout.EndHorizontal ();
        //First Row Amounts
        GUILayout.BeginHorizontal ();
        GUILayout.Box (dictionaryAmounts [0].ToString (), GUILayout.Height (20), GUILayout.Width(100));
        GUILayout.Box (dictionaryAmounts [1].ToString (), GUILayout.Height (20), GUILayout.Width(100));
        GUILayout.Box (dictionaryAmounts [2].ToString (), GUILayout.Height (20), GUILayout.Width(100));
        GUILayout.EndHorizontal ();

        //Second Row
        GUILayout.BeginHorizontal ();
        GUILayout.Button (InventoryNameDictionary[3], GUILayout.Height (100), GUILayout.Width(100));
        GUILayout.Button (InventoryNameDictionary[4], GUILayout.Height (100), GUILayout.Width(100));
        GUILayout.Button (InventoryNameDictionary[5], GUILayout.Height (100), GUILayout.Width(100));
        GUILayout.EndHorizontal ();
        //Second Row Amounts
        GUILayout.BeginHorizontal ();
        GUILayout.Box (dictionaryAmounts [3].ToString (), GUILayout.Height (20), GUILayout.Width(100));
        GUILayout.Box (dictionaryAmounts [4].ToString (), GUILayout.Height (20), GUILayout.Width(100));
        GUILayout.Box (dictionaryAmounts [5].ToString (), GUILayout.Height (20), GUILayout.Width(100));
        GUILayout.EndHorizontal ();

        //Third Row
        GUILayout.BeginHorizontal ();
        GUILayout.Button (InventoryNameDictionary[6], GUILayout.Height (100), GUILayout.Width(100));
        GUILayout.Button (InventoryNameDictionary[7], GUILayout.Height (100), GUILayout.Width(100));
        GUILayout.Button (InventoryNameDictionary[8], GUILayout.Height (100), GUILayout.Width(100));
        GUILayout.EndHorizontal ();
        //Third Row Amounts
        GUILayout.BeginHorizontal ();
        GUILayout.Box (dictionaryAmounts [6].ToString (), GUILayout.Height (20), GUILayout.Width(100));
        GUILayout.Box (dictionaryAmounts [7].ToString (), GUILayout.Height (20), GUILayout.Width(100));
        GUILayout.Box (dictionaryAmounts [8].ToString (), GUILayout.Height (20), GUILayout.Width(100));
        GUILayout.EndHorizontal ();
       

        GUILayout.EndArea ();

    }


}

Also how would i add tooltips?

anyone?

anything?

anyone?

First, Tooltips. Simple Gui.label should do, pretty basic but effective way to display text and values. Add a bit of textures to it, it’d look nice.

Second, don’t expect anyone to give you a completely working system from just your scripts. Making other people do all the work will never turn up right.

Third, the easy way to set up the system you’re saying is by simply finding the slot the mouse is over, and when it clicks, do exactly as you said. Make a new “slot” for the mouse, and when you click the slot, copy the contents to the “mouse” slot and then clear it. In theory, this would all be pretty simple. something like…

bool mouseHolding;
bool mouseovering;

void Update(){
    Vector2 mousepos = Input.mousePosition();
if(Input.GetMouseDown){
    clickedslot = getslotfrommousepos();
    if(clickedslot.info!=empty){   
        mouseslot.infot=clickedslot.info;
        clickedslot.info=empty;
        moseHolding=true;
    }
} else if (Input.GetMouseUp){
    mousedoverslot = getslotfrommousepos();
    mouseslot.info=empty;
} else if (mousedoverslot!= empty)
    mouseovering=true;
}

void OnGui(){
    if(mouseHolding)
        Gui.drawTexture(or whatever you wish to use for the label);
    else if (!mouseholding && mousovering)
        Gui.label(Tooltip!);
}

Notice, this would be a Drag 'n Drop inventory, not a click to pick up then click to put down system.

Something like that, if you fill in all the values with your own, should work. Sorry for it being so messy, I’m not on my PC right now.

You sound like a beginner? Why not begin at the beginning?

Thanks for this i have since restarted my inventory system and have implemented all of the things i needed it was due to the way i used the dictionary it kinda screwed me over

No problem.