How it works...

The Player class uses static (class) properties scoreCorrect and scoreIncorrect to store the current total number of correct and incorrect guesses. Since these are public static properties, any object from any scene can access (set or get) these values, since the static properties are remembered from scene to scene. This class also provides the public static method called ZeroTotals() that resets both the values to zero.

When the scene0_mainMenu scene is loaded, all the GameObjects with scripts will have their Start() methods executed. The UI Text GameObject called Text-score has an instance of the UpdateScoreText class as s script component, so that the scripts Start() method will be executed, which retrieves the correct ...

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.