コード例 #1
0
    void check()
    {
        RaycastHit hit;
        Ray        forwardRay = new Ray(main.transform.position, main.transform.forward);


        if (Physics.Raycast(forwardRay, out hit, 4) && Time.timeScale != 0)
        {
            if (hit.collider.isTrigger)
            {
                if (hit.collider.GetComponent <voxelHolder> ().interact(3) == "yes")
                {
                    Debug.Log("TOUCH WATER");
                    Item loot = hit.collider.GetComponent <voxelHolder> ().itemheld;
                    inv.AddItem(loot);
                }
                return;
            }
            if (hit.collider.GetComponent <voxelHolder> ().interact(3) == "yes")
            {
                Item loot = hit.collider.GetComponent <voxelHolder> ().itemheld;
                inv.AddItem(loot);
            }
        }
    }
コード例 #2
0
    public void BuyItem()
    {
        if (m_charectedInventory.IsFull())
        {
            Debug.Log("inventory is full");
            return;
        }

        if (m_charectedInventory.GetMoney() == m_charectedInventory.RemoveMoney(m_item.m_value))
        {
            Debug.Log("not enough money");
            return;
        }

        m_charectedInventory.AddItem(m_item);

        return;
    }
コード例 #3
0
ファイル: Slot.cs プロジェクト: tommoon/PlanetaryMinecraft
    public void OnPointerDown(PointerEventData eventData)
    {
        holder  = GameObject.FindGameObjectWithTag("InventoryCursor").GetComponent <iconHolder> ();
        inv     = GameObject.FindGameObjectWithTag("Inventory").GetComponent <inventory> ();
        descBox = holder.descBox;
        desc    = holder.desc;

        if (!holder.holding)
        {
            if (assignedTo.name != "nullItem")
            {
                holder.held    = assignedTo;
                holder.holding = true;
                holder.GetComponent <Image> ().enabled = true;
                holder.GetComponent <Image> ().sprite  = assignedTo.sprite;
                inv.RemoveItematPoint(assignedTo, slot);
            }
        }
        else if (holder.holding)
        {
            if (assignedTo.name != "nullItem")
            {
                inv.AddItem(holder.held);
                holder.held    = assignedTo;
                holder.holding = false;
                holder.GetComponent <Image> ().enabled = true;
                holder.GetComponent <Image> ().sprite  = assignedTo.sprite;
            }
            else if (assignedTo.name == "nullItem")
            {
                inv.AddItematPoint(holder.held, slot);
                holder.held    = assignedTo;
                holder.holding = false;
                holder.GetComponent <Image> ().enabled = false;
                holder.GetComponent <Image> ().sprite  = null;
            }
        }
    }
コード例 #4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Item")
        {
            Item item = collision.GetComponent <Item>();
            if (item.type == ItemType.SPELL_FIRE)
            {
                GameSaver.liveSave.spellTaken[0] = true;
            }
            if (item.type == ItemType.SPELL_ICE)
            {
                GameSaver.liveSave.spellTaken[1] = true;
            }
            if (item.type == ItemType.SPELL_PUSH)
            {
                GameSaver.liveSave.spellTaken[2] = true;
            }

            inventory.AddItem(item);
            Destroy(collision.gameObject);
        }
        if (collision.tag == "Chest")
        {
            chest = collision.GetComponent <ChestScript>().chestInventory; // gets inventory of chest
        }
        if (collision.tag == "Shop")
        {
            shop = collision.GetComponent <ShopScript>().shopInventory; // gets inventory of any shops
        }
        if (collision.tag == "Coins")                                   // gets the type of coin and then adds to total
        {
            CoinType tmp = collision.GetComponent <CoinScript>().type;
            collision.GetComponent <CoinScript>().AddCoins(tmp);
            Destroy(collision.gameObject);
        }
    }