Setting up the StateManager controller

Now, look at line 6 of the StateManager class in the following screenshot. We have a big problem right off the bat:

Setting up the StateManager controller

The activeState variable needs to be able to store all of the State types. Right now it can only store a reference to a BeginState type of object. This looks like a huge problem! What about the classes PlayState, WonState, and LostState? What if we had 50 different States that needed to be referenced in activeState?

The following diagram is our dilemma:

Setting up the StateManager controller

Studying an example of inheritance

Let's look ...

Get Learning C# by Developing Games with Unity 3D Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.