Beispiel #1
0
    private void InstantiateItem(Item addedItem)
    {
        GameObject emptySlot = null;

        foreach (Transform child in equipInven.transform)
        {
            if (child.childCount == 0 && emptySlot == null)
            {
                //emptyIndex = child.transform.GetSiblingIndex();
                emptySlot = child.gameObject;
            }
        }

        GameObject itemGo = Instantiate(item);

        itemGo.transform.SetParent(emptySlot.transform);
        itemGo.transform.position = emptySlot.transform.position;
        //RectTransform rt = itemGo.GetComponent<RectTransform>();
        //itemGo.GetComponent<RectTransform>().sizeDelta = emptySlot.GetComponent<RectTransform>().sizeDelta;
        DisplayItem disItem = itemGo.GetComponent <DisplayItem>();

        disItem.itemCount += 1; //num of items at hand
        disItem.DisplayItemGui(addedItem);
        ManageItem manItem = itemGo.GetComponent <ManageItem>();

        manItem.player      = gameData.GetComponent <Player>();
        manItem.equipmentGo = equipGo;
        Button itemBtn = itemGo.GetComponent <Button>();

        itemBtn.onClick.AddListener(delegate() { SelectItem(itemGo); });
    }