Unit class inheritance

Hi all, I’ve seen in other videos the use of inheritance it seems like a good spot to use it here,

the UnitSpawner, UnitBase have shared attributes and methods such as:
ServerHandleDie, ServerOnSpawned, ServerOnDesppawned, and maybe we can add
UnityEvenNetworkConnection onSelected and onDeselected to play sounds/visual of selecting for the player.

Health bars also seem genertic enough to be placed into the Unit anyways inheritence looks like it will reduce code here

Hi there,

I like the thinking here!

However, I think inheritance is not used in this case as those methods diverge later in the classes. It might be possible to create a base class with virtual methods and have them be overridden by the child classes. Also, inherited private properties are not accessible from the child class, so those would need to be modified to be exposed, which might not be ideal.

The events especially are class specific. The game needs to react differently if a regular building is destroyed verses a base.

Another approach might be to create a new class with some of this shared code. Else move the code into a class already on all these gameObjects like the unit or building class.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms