How it works...

As can be seen in the following state chart figure, this recipe models a simple game, which starts in the GamePlaying state; then, depending on the button clicked by the user, the game moves either into the GameWon state or the GameLost state. Also, if the user waits too long (five seconds) to click on a button, the game moves into the GameLost state.

The possible states of the system are defined using the enumerated GameStateType type in the GameStates class, and the current state of the system at any point in time is stored in the currentState variable of GameManager:

The initial state, GamePlaying ...

Get Unity 2018 Cookbook - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.