Hi Guys,
I have been working on a game for awhile now and I want to add an inventory and crafting system. I have tried looking at all sorts of tutorials but none of them are what I need or they end before the finish. I am posting here today because I want to know how I would even go about the coding for an inventory/crafting system. I was hoping someone had a link to something similar to what I am looking for or they could torture themselves helping me.
I am looking for an inventory that when opened has slots for multiple items. (C# if at all possible ) The items can stack and you have a weight limit.Also if you hover over an item on the ground text will appear “Pick Up “x” Item” when interacted with the item will be added to the inventory. When you open the inventory there is a crafting bar that displays the item you can make and the items needed, and when clicked you get that item and the items used to craft it are gone. Furthermore I would like to implement storage crates and different crafting stations.
Well most of what you posted is simply data structures. Try implementing an inventory system from any of the tutorials you find to get a feel for what they are doing. No inventory tutorial will exactly match what you need. The idea is you create class(es) to handle your inventory. You will use probably do something like create a class that represents one item. This class will have details about what attributes an item might have. Then have some kind of class that is a storage class. Its just a wrapper to keep track of what items are in it, and what quantity. Your main inventory class will have an array or List of these containers.
You will also implemnt things to remove or add items to this Inventory, which will properly increment the various containers, or add new items to them.
Your quote here:
Also if you hover over an item on the ground text will appear "Pick Up "x" Item"
Has nothing to do with an inventory system. It will be part of the main game. Now when they actually do press X… then some script in your game will detect that, figure out what item they clicked over, destroy it off the scene and call your Inventory’s add Item methods.
Crafting system should be an entirely separate entity from Inventory. It will be similiar to an inventory system but will have its data structures. It will contact the Inventory Manager to get data on what items you have so it can populate its own data.
Inventory and Crafting systems are extremely broad subjects. If it seems to hard to get going step back and implement a much smaller idea. Try making a game that has say 4 differnt objects in the world (colored spheres maybe). They have colliders and when you run over them they disappear and show up in your “inventory”. Make an inventory class that can keep track of these 4 items. Figure out a way to display 4 boxes somewhere on your screen when you press the inventory Key. ANd get the data from the Inventory class and display the correct data in those boxes.
If you try making various inventory systems starting very basic and getting more advanced you’ll see that they are pretty much the same… Your just tweaking the data structures to exactly match what you need for your game.
Thats probably just going to be some equipment class on your player. So your gameUI that is presenting the inventory (and you should have the inventory data separate from the graphics UI that is presenting it.) , might have the ability to right click an item being shown and equip. Then that right click equip button would call some methods on your inventory to get the item, and remove it … then you’d equip it to your player’s equipment class. Modular is best when designing these things.