In my game I have some objects in the game that the player can interact with. When interacting with these the player can request certain things at a certain time delay. Think of it as them orderings something. They are able to order multiple things from any one object and each thing may take a certain time to return.
When the item is ordered I add it to a dictionary in my singleton script as below:
var dict = {"OBJ1": { "Item": 10, "item2": 60}, "OBJ2": {"Item3": 55, "Item7": 90}, etc.}
Now i have a function that fires every second and filters through all of these reducing the number by a second and when 0 is reached the player is told that that item is ready to collect from that object.
This works fine but I am querying whether it is the most efficient way of doing this or may there be a better way of performing this action. I also was wondering if this function should be a new thread? Could somebody perhaps give me some guidance on when functions should be threaded and when not?
Thanks!