예제 #1
0
    /// <summary>
    /// This function adds a new item to the list to the list it also calls the inventoryEventArgs
    /// to be displayed in the inventory.
    /// </summary>
    /// <param name="item"> Requires an object of type I_IventoryItem</param>
    public void AddItem(I_IventoryItem item)
    {
        //  checks to make sure that no more items can be added than the max slots
        if (mItems.Count < SLOTS)
        {
            // gets the collider properti from the item as a MonoBehavior insted of the I_IventoryItem
            Collider2D collider = (item as MonoBehaviour).GetComponent <Collider2D>();

            // If the Item collider is set on the item colider will be disable and the item will  be added to
            // list of mItems  and the item onpickup is called which disables the object
            if (collider.enabled)
            {
                collider.enabled = false;
                mItems.Add(item);
                item.OnPickup();


                //calls the event for the item
                if (ItemAdded != null)
                {
                    ItemAdded(this, new InventoryEventArgs(item));
                }
            }
        }
    }
예제 #2
0
    /// <summary>
    /// This Function is called when the player collides with an item. IF
    /// the item has componet of type I_IventoruItem than i gets added to the
    /// inventory.
    /// </summary>
    /// <param name="hit"> Colllision2D details of the item</param>
    private void OnCollisionEnter2D(Collision2D hit)
    {
        I_IventoryItem item = hit.gameObject.GetComponent <I_IventoryItem>();

        // if the item is the script the item proceds to call the iventory
        if (item != null)
        {
            // reference to the Additem function in the class inventory
            inventory.AddItem(item);
        }
    }
예제 #3
0
 public InventoryEventArgs(I_IventoryItem item)
 {
     Item = item;
 }