コード例 #1
0
ファイル: PlayerInventory.cs プロジェクト: JKneedler/ASCII
    public void PressedButton(string optionName)
    {
        MenuController menuC           = gameObject.GetComponent <MenuController> ();
        ItemsForPickup curTile         = gameObject.GetComponent <PlayerMovement> ().currentTile.GetComponent <ItemsForPickup> ();
        PlayerEquipped eq              = gameObject.GetComponent <PlayerEquipped> ();
        int            curInvSlotIndex = (int)currentInvSlot;

        switch (optionName)
        {
        case "Drop":
            GameObject itemToDrop = menuC.curNode.children [menuC.index].item;
            curTile.AddItemToTile(itemToDrop);
            RemoveItem(menuC.curNode.children [menuC.index]);
            if (invNode.children [curInvSlotIndex].children.Count == 0)
            {
                invNode.children [curInvSlotIndex].AddChild(new Node("No Items found here."));
            }
            break;

        case "Equip":
            GameObject itemToEquip = menuC.curNode.children [menuC.index].item;
            ItemInfo   it          = itemToEquip.GetComponent <ItemInfo> ();
            for (int i = 0; i < eq.slots.Length; i++)
            {
                if ((int)it.slotPos == (int)eq.slots[i].slot)
                {
                    eq.EquipItem(itemToEquip, eq.slots [i].slot);
                }
            }
            break;
        }
    }
コード例 #2
0
    public void BreakDown()
    {
        bool           canBreakDown = true;
        GameObject     player       = GameObject.FindGameObjectWithTag("Player");
        PlayerEquipped eq           = player.GetComponent <PlayerEquipped> ();

        if (reqTool != tools.any)
        {
            if (eq.slots [0].equippedItem != null)
            {
                ItemInfo it = eq.slots [0].equippedItem.GetComponent <ItemInfo> ();
                if ((int)it.toolType != (int)reqTool)
                {
                    canBreakDown = false;
                }
            }
            else
            {
                canBreakDown = false;
            }
        }
        if (canBreakDown)
        {
            gameObject.AddComponent(typeof(ItemsForPickup));
            ItemsForPickup it = gameObject.GetComponent <ItemsForPickup> ();
            it.CreatePickUpNode();
            foreach (GameObject item in drops)
            {
                it.AddItemToTile(item);
            }
            SpriteRenderer thisSprite = gameObject.GetComponent <SpriteRenderer> ();
            thisSprite.sprite = groundSprite;
            gameObject.tag    = "Untagged";
        }
        else
        {
        }
    }