I'm currently working on a crafting system - this systems works fine when the desired item has only one requirement. If there is more then one requirement the system brakes.
Here's a short description of how the system should work:
- Every object has a monobehaviour-script which holds an scriptable object.
- This scriptable object contains all the statistics and has a list of required items.
- The warehouse has a monobehaviour-script and this has a list of content items.
- To craft a new item it should compare the content with the requirements.
- Based on the output the object will spawn.
The my problem is getting the right output.
Item Class:
[System.Serializable] public class Item { public ScripableTradegood scripableTradegood; public int amount; } Warehouse:
[Header("Warehouse Content")] public List<Item> warehouseContent; Scriptable Object:
[Header("Requirements")] public List<Item> tradegoodRequirements; Here the problem:
// Loop through the requirements foreach (Item requirement in tradegoodRequirements) { // For each requirement check content in warehouse foreach (Item content in warehouse.warehouseContent) { // When content is not requirement skip the check if (content.scripableTradegood != requirement.scripableTradegood) continue; // When right content was found if (content.scripableTradegood == requirement.scripableTradegood) { // If required content amount isnt present return if (content.amount < requirement.amount) return; /* * When the tradegood has only one requirement - I could just substract the requirements and exit out of the function. * But when if I have more then one requirement - how can I check if all requirements a present before substracting them? * Logically I would have to leave the second loop and continue to check the requirements from the first loop - But how can I achieve that? * */ } } } Where is my mistake? Is there something wrong with my approach?