Ejemplo n.º 1
0
    // Randomly picks items from the list and adds them to the inventory.
    private void RandomAdd(List <ItemContainer> itemToAdd, int howMany)
    {
        int random = Random.Range(0, itemToAdd.Count);

        for (int i = 0; i < howMany; i++)
        {
            //  Picks a random item
            ItemContainer temp = itemToAdd[random];

            /*
             *  If the item is already in the inventory, then randomly pick another item
             *  until its an item that doesn't exist in the inventory already.
             */
            while (inv.FindItemByContainer(temp) != null)
            {
                random = Random.Range(0, itemToAdd.Count);
                temp   = itemToAdd[random];
                if (inv.FindItemByContainer(temp) == null)
                {
                    break;
                }
            }

            //  Adds the item to the inventory.
            inv.AddItem(itemToAdd[random]);
        }
    }