In this tutorial, I will teach you how to use PlayerPrefs save system in Unity.
First of all, you need to add a canvas that will have a Text object, along with a Button. The text object will be a value, by default it will be set to 0. The button will be interactable and will increase or decrease the value. There will also be two buttons, that will be used for saving and loading. When you create those two elements, you need to create a C# script. Just add it in the Canvas object and name it SaveSystem.
In the void Start you need to add an if statement. This statement checks if there is a key named scorevalue. to make playerprefs system do anything to the project, you need to assign it to the score value. The score value will be called in a PlayerPrefs.GetInt, which is the method that will be used for loading the value from the saving system.
PlayerPrefs, on the other hand, has many other ways to communicate with data in Unity. It is very practical for a project that keeps a small amount of data, such as current level, highscore and lives count for your player, but is also useful to save game settings such as music volume. PlayerPrefs has some additional features such as DeleteKey, which deletes a specific key from a project until it is created again, DeleteAll for deleting all keys and values that exist in a project.
This saving system has three ways of saving data: Save, which is used for saving all preferences, setfloat, for saving a float value, setInt, for saving an integer value and setstring, for saving a single string value.
I would recommend you to use JSON saving system if you are working on a bigger project, since it is more practical for larger data files and can work better if you have to save positions, items, and various objects that are not supported in PlayerPrefs saving system.
Support the Creator of Kozmobot on the social networks!
CHECK OUT MY WEBSITE: http://kozmobot.com
INSTAGRAM: https://www.instagram.com/kozmobot.channel
TIKTOK: https://www.tiktok.com/@kozmobot.channel
Voir sur youtube