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 ();
}
}