コード例 #1
0
    public void EquipItem(GameObject itemId)
    {
        if (itemId != null && itemId.GetComponent <AbstractItem>().itemType == "Equipttable")
        {
            AbstractItem itemscpt = itemId.GetComponent <AbstractItem>();

            if (!itemscpt.equipped && equippedSlots.Any(x => x.GetComponent <SlotInfo>().item == null))
            {
                if (itemId.GetComponent <AbstractItem>()._armorType == (int)AbstractItem.armorType.Head)
                {
                    itemId.transform.position = GameObject.FindGameObjectWithTag("Player").transform.position + new Vector3(0, 0.65f, 0);
                }
                else if (itemId.GetComponent <AbstractItem>()._armorType == (int)AbstractItem.armorType.Body)
                {
                    itemId.transform.position = GameObject.FindGameObjectWithTag("Player").transform.position + new Vector3(0, 0, 0);
                }


                itemscpt.equipped = true;
                itemscpt.EnableItemEffect();
                itemId.transform.SetParent(GameObject.FindGameObjectWithTag("EquippedItems").gameObject.transform);

                //Debug.Log("EQUIPPED: " + itemId.name);
            }
            else if (itemscpt.equipped)
            {
                itemId.transform.position = GameObject.FindGameObjectWithTag("ItemsFolder").transform.position;
                itemscpt.equipped         = false;
                itemscpt.DisableItemEffect();
                itemId.transform.SetParent(GameObject.FindGameObjectWithTag("ItemsFolder").gameObject.transform);

                //Debug.Log("UNEQUIPPED: " + itemId.name);
            }

            //Items.RemoveAt(itemId);
        }

        SlotsUpdate();
    }