Making a RTS game #7: Polymorphism, take 2! (Unity/C#)

Let’s continue our RTS game and focus on the hierarchy of our classes!

Mina Pêcheux
CodeX
Published in
5 min readApr 22, 2021

--

⬅️ 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 a UnitData class
  • instance — the Building class should inherit from a Unit class

Proxying for the data classes (UnitData/BuildingData)

--

--

Mina Pêcheux
CodeX
Writer for

I’m a freelance full-stack web & game developer. I’m passionate about topics like CGI, music, data science and more! Find me at: https://minapecheux.com :)