I have a sandbox world in Unity with various GameObjects that will eventually have a set of interactions that the player can choose from once they click on this object (best example would be The Sims).
I basically want each object to contain a list of methods which have been assigned from another list of methods. So maybe there is a Tree with the “shake” method, I want to assigned the “shake” method to the Tree’s interaction list but the shake method is defined in another class. I also might have a car which could also have the “shake” method.
I understand that I can have a list of Action.
List<Action> interactions = new List<Action>();
and that this list can be populated with methods but Is this the best solution for what I explained above, and can i somehow have a Enum with all possible interactions which would automatically call a particular method for the particular GameObject?
I don’t know exactly what you’re trying to achieve and whether it is the best solution, but to me this sounds like a good use for the strategy pattern: