I needed a program that could pick from a bunch of ingredients to create random omelet recipes, because I’m record breaking lazy.
Each ingredient needed to have a name, some categories, and a rank, so that the user can distinguish between ingredients, opt to only have ingredients with certain categories(Like Veggies only) and influence the frequency of certain ingredients that they like.
I thought maybe I would have a recipe script that would generate the recipe by picking from a list and editing the text component of the text object the script is on. I’m still testing things out because I’ve never done these kinds of things and I’m trying to learn.
I made the Ingredient class, which does not inherit from MonoBehavior.
public class Ingredient{
public string itemName = "";
public string[] categories; //Struggling to implement these
public int itemRank = 10;
public Ingredient(string newItemName, int newItemRank)
{
itemName = newItemName;
itemRank = newItemRank;
}
}
And here is the recipe class.
public class Recipe : MonoBehaviour {
public List<Ingredient> ingredients = new List<Ingredient>(); //Uses my class as the type
public Text recipeUI;
void Start()
{
ingredients.Add(new Ingredient("Bacon",10)); //Makes an ingredient called bacon with a rank of 10
recipeUI.text = ingredients[0].itemName;
}
}
Things seem to be working the way I want them to, despite it being a little over my head. I just can’t think of how to add categories. I thought maybe I could add the categories array to the Ingredient method as a constructor, but then I don’t know how to pass the category information when I add new items to the list, and I imagine that would be very messy anyways. How might I implement categories to the ingredients?
Or if you have any ideas on a better way to make my program I’m all ears.
EDIT: I simply added the categories afterwards, and now I feel silly. Since I can’t seem to delete this thread, I’ll leave it for criticisms of my methodology.