- Home /
Crafting items. Best way to do it?
Hey,
so I am working on a 2D survival game and i am struggling a bit with finding the right way to make crafting work. so what I currently have (that work) is that i check a list with all my inventroy item. and if the right amount of items(crafting recipe is also a list) that you need to craft an item are in there the item that you can craft will add to another list. now what is the best way the check if you can craft an item. i'm currently thinking about 2 option - option 1: I put all the crafting recipes in 1 script and run them trought the inventory list. - option 2: I make a 'fake' copy of all craftable item in the world scene with only the crafting recipe variable on them.
Option 1 think will take a much bigger script but with option 2 you"ll have a shorter script but you have all those item copy's in the world. and i cannot put the crafting recipe in prefab (right?). because the game won't load them.
how option 1 would look in my game:
Public List<string> item1
public List <int> item1amount
public List <string> item2
public List<int> item2amount
public List<string> item3
public List <int>item 3 amount;
public List<string> inventory items
void {
if (inventory.contains(item1))
{
*my system to check amount of items about 3 (this isn't important now*
{
add item 1 to craftable items list
}
}
if (inventory.contains(item2))
{
*my system to check amount of items about 3 (this isn't important now*
{
add item 2 to craftable items list
}
}
if (inventory.contains(item3))
{
*my system to check amount of items about 3 (this isn't important now*
{
add item 3 to craftable items list
}
}
ass you see this would be a very large script(or is there maybe a way to run multiple list throught another list) but otherwise you just have the lines for item1 in 1 script attached to every item then i put in the needed in for each.
i don't know if everything is clear if not just ask adn thank you for trying to help.