Im creating a simple Point & Click game. If the player clicks on an object, the “Clicked” function in the “Clicked” script of that object is executed. Now I want different things to happen when the player clicks on different objects. Is there a way to call the same function on different objects, but having different code being executed?
1: Inherit from your click script
For each different thing that needs to happen, make a new script, that inherits from your click script. In that script program a custom click method.
2: Reaction scripts
Make a new interface “reaction”. Then make a bunch of reaction scripts for each of the different things you need an object to do (each implements the reaction interface.) Then add new reaction components to your object, and in the start of you click script collect there (GetComponents<…>()). In the click script, when ‘Clicked’ is called, call all the “React” methods of your reactions.
Hope this helps.
If you don’t know inheritance or interfaces, you should probably google them, they are pretty basic and not that hard.