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