This tutorial shows how to use player preferences. They allow you to store user data between sessions and can be used for un-lockable content. To create the scene above, we make a list of locked items that will be iterated through.
On Start () we reset everything for testing purposes and set each player preference to a variable. If the PlayerPrefs.DeleteAll line from above was commented, the values of the player preference variables would persist from scene to scene and when the game was stopped and started. We add all of those variables to a list of ints using a static extension function that allows us to specify the list as the first parameter and then add how ever many elements we want as following parameters. All of these following elements are then added to the list.
Now we see which items are locked.
First, we iterate through all of the pre-defined lockable items. They each have a script with a unique ID representing the amount of game play throughs needed to unlock them. Those values are checked against PlayCount to see if the item is unlocked or not, thus turning it green or red. We also update the player preference int and then can code logic if the player preference has recorded the object as being unlocked.
When an event calls Count and Subtract,we change the PlayCount and are also able to unlock everything or reset all of the player preferences.
Make a free website with Yola