The scene is very straightforward for this recipe. There is the single Main Camera GameObject that has the MyGameManager script object component attached to it.
A C# scripted class is defined for each state that the game needs to manage—for this example, StateGamePlaying, StateGameWon, and StateGameLost. Each of these state classes is a subclass of GameState. GameState defines properties and methods that all subclass states will possess:
- An enumerated type EventType, which defines the two possible button click events that the game might generate: ButtonWinGame and ButtonLoseGame.
- The gameManager variable so that each state object has a link to the game manager.
- The constructor method that accepts a reference to MyGameManager ...