First Android Game - Part 21 - Save data - PlayerPref Nov 13, 2023
This is part 21 of making my first Android Game. If you missed part20, you can find it here. Playerpref allows users to store player preferences between game sessions. It can store strings, floats and integers on the user's registry as explained here. Below is an example of how I press S to set a key to 24 called "EldonTestInt", press G to get the key and D to delete the key On windows 10, when I save this value, it will appear in register editor Computer\HKEY_CURRENT_USER\SOFTWARE\Unity\UnityEditor\Company Name\Product Name. Company name and Product name are the names set in Player Settings What if I want to save more data using JSON? Following the tutorial here< First I add a custom class so and make it System.Serizlizable to that JSON can read it In Update() when I press "J", I would create a new instance of the class and hardcode the values of player's name, health and score. I would set the results to a key called SavedPlayer and save the key. When I press "L" I would display the values on to the screen I'll double check in UnityRegistry that the SavedPlayer key is actually saved I exit play mode and enter play mode, but this time I press "L" to load the values because I've already pressed "J" on the last play session so the SavedPlayer key should be saved locally. As you can see from the iamge below, the values are still saved! See part 22 here
Recent blogs See all blogs