0
\$\begingroup\$

I encountered a problem where I want to make a Scriptable Object that derives from another class, but C# does not support multiple inheritance. Further, I do not think it would not make sense to make interfaces for this example. There is a lot of duplicate code within methods that only an abstract class could contain implementations of.

Basically, I want an abstract class that models "anything that can take a turn." I call it a TurnTakeable. But I also want the TurnTakeable to be split into friend and foe derived types, as the two are slightly different. Yet they mostly have the same behavior.

Is there a workaround, or do I have to make an interface? :(

\$\endgroup\$
7
  • \$\begingroup\$ Any reason things can't be split into components? \$\endgroup\$
    – Sidar
    Jul 24, 2017 at 22:36
  • \$\begingroup\$ @Sidar, could you be more specific? \$\endgroup\$ Jul 24, 2017 at 23:49
  • \$\begingroup\$ You're using unity and you want to your objects to have certain functionality. Can you not split them up in components rather than a inheritance tree? \$\endgroup\$
    – Sidar
    Jul 25, 2017 at 0:37
  • \$\begingroup\$ I'm new to this concept. Can you give an example? \$\endgroup\$ Jul 25, 2017 at 0:58
  • \$\begingroup\$ It makes sense to me that a "thing that can take a turn" is a Scriptable Object. Further, I want those things to be able to have some shared functionality like take a turn, die, attack, defend, etc. \$\endgroup\$ Jul 25, 2017 at 1:04

1 Answer 1

-2
\$\begingroup\$

I decided to make the abstract class the scriptable object.

\$\endgroup\$
1
  • \$\begingroup\$ You'd have to show more for an answer than this. This won't help other people. \$\endgroup\$
    – Sidar
    Jul 25, 2017 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .