Making a RTS game #7: Polymorphism, take 2! (Unity/C#)
Let’s continue our RTS game and focus on the hierarchy of our classes!
⬅️ Tutorial #6: Improving the UI | TOC | Tutorial #8: Boosting our selection feature ➡️
📕 Get the ebook and bonus material on Gumroad!
🚀 Find the code of this tutorial series on my Github!
In this tutorial, we are going to reorganise some of our classes to better prepare what’s to come: we will create a clear logical hierarchy for our units that can be either buildings or characters. We started that process in a previous episode of this series, but we’re not done yet.
At that point, you might realise that we could — and should! — re-use the notions of inheritance and polymorphism we saw in the previous tutorial for our data and unit classes. What we want is to replicate the kind of class hierarchy we have between UnitManager
and BuildingManager
at two levels:
- data — the
BuildingData
class should inherit from aUnitData
class - instance — the
Building
class should inherit from aUnit
class