How do I like count how many different types of items, how many of them and return that value, use it quickly in my crafting script. So the recipe calls for 2 wood, 4 stone, it calls the CheckForItemsAndReturn() with (wood, 2), and (stone, 4), then adds the two lists, and then uses generic list.sort() and compares the two, if they are the same, then they would continue the craft method.; Thanks, Huskypanda
Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerInventory : MonoBehaviour {
public int MaxInventory = 26;
public List<Item> InventoryItems = new List<Item>();
public void AddItem(Item _item){
}
public void Craft(CraftingItem Recipe){
Recipe.InputItem.Sort ();
List<Item> _items = new List<Item> ();
//Find out the number and use CheckForItemsAndReturn();!
if (Recipe.InputItem == _items) {
foreach(Item _it in _items){
InventoryItems.Remove(_it);
}
InventoryItems.Add(Recipe.OutputItem);
}
else{
Debug.Log("Invalid Items.");
}
}
//For Multiple
public List<Item> CheckForItemsAndReturn(Item checkfor, int count){
List<Item> il = new List<Item>();
foreach(Item it in InventoryItems){
if(it == checkfor){
if(il.Count <= count){
il.Add(it);
}
}
}
return il;
}
}