I am working on adding selection and interaction to my game. The Selection part (for my player) is not too difficult - I'm using the raycast-from-camera method to click-select. Selectable objects have a Selectable script attached to them so I can tell whether they can be interacted with.
My question is about how people structure their code to manage this interactivity. Different objects have different actions (e.g. pick up, open, press). Different characters may be able to perform different actions. Some actions may have other constraints (e.g. need a specific key or other item).
The selection code will need to combine all of these data to determine the available actions and offer options to the player. When an action is executed, it may need to affect the object (e.g. the door opens), the character, or both (e.g. the character's inventory gets the item, the item's game object is destroyed).
I am wondering if anyone has pointers, suggestions, tutorials, etc. that help keep this manageable since it can easily become a complicated mess... Do you have some kind of separate data structure that defines all possible actions and assigns them to specific items and characters? Subclassed behavior classes that define each possible action? How do you match up the "actions item offers" with the "actions character can perform" and then execute the correct code on each end?
I don't want to keep all of this code in my player-character, because I'd like to use the core functionality for NPCs as well (just add the GUI interface for the player)...