Book Image

Unity Game Development Blueprints

By : John P. Doran
Book Image

Unity Game Development Blueprints

By: John P. Doran

Overview of this book

Table of Contents (16 chapters)
Unity Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 two key functions for each of the types Get and Set with the type added afterward (GetFloat, SetString, and so on).

The Set functions

The Set functions take in two parameters: the first being a string and the second of the type you're trying to set. This...