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\$
  • \$\begingroup\$ Any reason things can't be split into components? \$\endgroup\$ – Sidar Jul 24 '17 at 22:36
  • \$\begingroup\$ @Sidar, could you be more specific? \$\endgroup\$ – reincarnationofstackexchange Jul 24 '17 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 '17 at 0:37
  • \$\begingroup\$ I'm new to this concept. Can you give an example? \$\endgroup\$ – reincarnationofstackexchange Jul 25 '17 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\$ – reincarnationofstackexchange Jul 25 '17 at 1:04
-2
\$\begingroup\$

I decided to make the abstract class the scriptable object.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.