Hi Unity,
I am about to start creating my own crafting system and I am looking for some help on my theory before I jump in head first.
What I have today is a basic inventory system based around an Item script which defines what an item is and gives it things like an icon, tooltip, and other properties.
I have the ability to collect items in the game and add them to my inventory.
Now what I am looking to do is create a GUI window that allows you to put items in it and checks to see if you have certain items, if you have those items, in a gui box to the right a craftable item will show up.
So here is how I plan to implement this - and I am trying to find a better way to set up the recipe system:
Using OnMouseDown to detect if player has clicked on crafting table, if so GUI window pops up.
Use a for Loop to loop through current items in the players inventory.
(Now here is where I need some help to figure the best way to do this)
My original thought, which I think is probably terrible, is have a seperate set of variables in my crafting class, basically one variable for every item in the game.
As I loop through the player inventory, I can check if item.name == whateverItem. If it is, I increase a counter for that item.
Then after the for loop I can check the count for all my variables and if I have one of each of the items needed for itemX, then that icon shows up.
Something maybe like this?
private string basicWoodName = "basicWood"
private int basicWoodCount= 0;
private string basicStoneName = "basicStone"
private int basicStoneCount = 0;
for(int cnt; cnt < itemScript.playerInventory.count; cnt++)
{
if(itemScript.playerInventory[cnt].name == basicWoodName)
{
basicWoodCount++;
}
if(itemScript.playerInventory[cnt].name == basicStoneName )
{
basicStoneCount++;
}
}
//I would need one of these for every item.. ouch
//Then I would need recipe's - something like this maybe? (terrible I know)
if(basicWoodCount == 6 && basicStoneCount == 1)
{
//Show GUI Icon for a Sword
}
//I would need one of these for every possible combination.. Ouch
I would like to just use a List for this somehow, but i cant figure out how I would access the invidivual items in the list to see if I have what I need.
Of course I will need to add a lot more to this script but I am just trying to formulate the basic idea of how this is going to work.
Thoughts on a better way to do this before i start?
Thanks!