Interacting with indexed items based on Enum

I hate to get answers like that by myself but you should change your approach:
Using an Interface is a good idea for this but also using the ENUM is redundant and dont uses the potential of an interface.
What i would recomend:

  1. Define a Function like “Interact” inside of your interface. (No Idea how deep you are into OOP, but that will enforece every object that implements this interface to also implement the Funtions of this interface)
  2. Implement the functions for different Objects. The cool thing is that every object than has its own behaviour for calling this one function.
    (for example: open/close logic for your door inside the door object)
  3. Call this interact function from your player, without caring about witch kind of interactable object it is.

Its very common to use this practice and will make it very easy for you to implment more interactable objects, becaus you only have to look on the one object you working and not on the “caller-object”

I can give you more details abou this aproach if you need.

1 Like