Playerprefs Introduction

When we are making our games, always, has many requirements, on way our way, and a of these, is saving data, regardless of the reason, to save information, always is presents on our contexts.

Firstly, we need know that Unity has a property for save data in memory, this property is named Playerprefs.

With playerprefs is possible, salve all data types, although he is do not offers support for Boolean data, is possible to convert this data into binary using integers values for so to effect the saving.

For to work with Playerprefs is fundamental to understand that exist Set methods, and Get methods.

The Set methods are responsible for save data in memory, and the Get methods, are responsible, for to access the data.

Below we have a list with some Playerprefs Methods:

PlayerPrefs.SetInt();
PlayerPrefs.SetFloat();
PlayerPrefs.SetString();

PlayerPrefs.GetInt();
PlayerPrefs.GetFloat();
PlayerPrefs.GetString();

For to begin to save data with Playerprefs is necessary give a variable entre “ “, so after this, we use a , and the variable’s name or the code’s value that will be necessary to save, for example:

PlayerPrefs.SetInt(“YourPlayerprefsVariable”, 15);

Also is possible to delete Playerprefs variable’s content using the method, DeleteKey or DeleteAll.

The DeleteAll method will to delete all data that were saved by Playerprefs, his syntax is:

PlayerPrefs.DeleteAll();

E o método DeleteKey, serve para deletar o conteúdo de uma das variáveis PlayerPrefs que foram salvas, a sintaxe dele é a seguinte:

PlayerPrefs.DeleteKey(“SuaVariavelPlayerPrefs”);

After a introduction you is ready for to save data with Unity PlayerPrefs, this is a very simple and very fast method for to save.