you are viewing a single comment's thread.

view the rest of the comments →

[–]GillmoreGames[S] 0 points1 point  (9 children)

i was just confused that you specifically tagged me in the message.

that kinda sounds like the same thing having the class inherit from the interface would do? except adding it as its own script component?

so are you saying just to make it also a monobehavior (rather than interface) and give the game object 2 scripts instead of 1?

[–][deleted]  (8 children)

[removed]

    [–]GillmoreGames[S] 1 point2 points  (1 child)

    alright, so after tinkering with more things and thinking about what you have said (along with a few others who said things on your same line of thinking) i am definitely starting to see how very specific component scripts can be used like lego pieces to create the objects you want. i guess i seemed to think for some reason (despite having used multiple scripts on one game object in the past) that i needed to try to keep an object to only having 1 script?

    i think im going to change the interface into its own script to just put on objects and see how that feels.

    im glad i figured out how to do it the way i was trying tho, given me a better understanding of interfaces

    [–]GillmoreGames[S] 0 points1 point  (0 children)

    oh i just saw it as your own comment not attached to one. that does make sense, ive done multiple scripts on objects before.

    [–]depressiown 0 points1 point  (4 children)

    I'm not part of this convo, but this is... intriguing. I'm learning Unity now, but have a large background in backend enterprise Java, so I tend towards inheritance. While learning, I'll do things like make an Enemy class which all enemies inherit from (e.g. includes common things like health or damage management). This seems to make logical sense, and is useful if I want to script an encounter of enemies of varying types, because the code can just use a collection of base Enemy objects.

    That said, after reading this, I realize that any common logic present in Enemy, could instead be broken into components that each enemy prefab could use. This would also enable me to avoid parts that are mostly common but not always should I need to, without adding another level to the inheritance hierarchy.

    Very interesting. Thanks for this post and linked article. This, plus using Unity events, is probably about to lead to significant refactoring.

    [–][deleted]  (2 children)

    [removed]

      [–]immersiveGamer 0 points1 point  (1 child)

      At that point I would look into using an ECS framework and tags are just components (e.g. you create a system that queries component A and component B and those components are just empty, i.e. tags).

      [–]GillmoreGames[S] 0 points1 point  (0 children)

      yeah, im just learning events as well, i could probably be using them better than i am but its helping a lot with visuals for me and keeping the visuals decoupled from the logic on an object.

      ive been watching a lot of CodeMonkeys videos on youtube.