Saving a high score

To begin with, let's look at one of the simplest ways to save/load data for individual pieces of simple data using the PlayerPrefs class.

The PlayerPrefs class

The PlayerPrefs class allows us to store small amounts of data on the end user's machine. Using PlayerPrefs is a great way to save data for user levels, the coordinates of where enemies are, or a high score so that when the user comes back to the game, it shows the highest score achieved over the course of all games played.

When I say small amounts of data, on the WebPlayer you can store only 1 MB of data, but this is the only limitation aside from hard drive space as of this writing.

The PlayerPrefs class can store the following types: float, int, and string. There are ...

Get Unity Game Development Blueprints 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.