- Home /
The question is answered, right answer was accepted
Multiple scripts vs arrays vs lists?
HI everyone!
I'm developing a mobile game where you can tap on trees to get a fruit drop or use an axe to chop them and get some wood. If you chop a tree, it then starts growing again. Every tree has to store it's own time variables like "lastTimeDrop" and "timeLeftToGrow" so I can check if the tree has grown or if it can give the player another drop.
My problem is that I don't know which is the best aproach to handle all the trees. Should I have an array with all my trees and other arrays with their varaibles and check them all every second? Should I use Lists? Is better to have every tree with a script (same script for all of them) ? Any help will be apreciated!
Also, how can I track every tree between game sessions to know which tree has grown, which tree can drop something, etc.?
Thank you very much for your time,
Sergio
This is a wide question. You should research and experiment to find the answer.
I will advise you to not check the status of every tree every second. Its not that time critical so you should save on processing.
Consider groups of trees with a Tree-$$anonymous$$anager LOCAL to the group. This will help prevent needless processing. Dont have 1 manager for every tree or each tree handling their own.
Just my opinion, but that is exactly why this should be on the forum and not on UA :)
Totally agree with @meat500. I use the approach to have "$$anonymous$$anager" to manage a group of items, and a "Controller" to manage a single item of the group. Some things like animations and stats I like to have individual, but some others makes more sense to have a group manager to deal with. $$anonymous$$ake some tests
Hey! Thank you both for your time! I'll follow your advice and make some tests to see what's better. And you're right, this could lead to a further discussion more proper for forums haha