O'Reilly logo

Learning C# by Developing Games with Unity 3D Beginner's Guide by Terry Norton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required