Saving Players' Progress By Using PlayerPrefs
Hello everybody and I apologize for my bad English.
I've made a mobile game for iOS and Android terminals, and I wanna know how to make a saving data system to save the players' progression ? I found out that we could use PlayerPrefs but I don't know how to do it. So, when we finish a level, the next level will be possible to join. In the List Levels scene, you can actually select this level, but not the next level unless you've done this one. So when a level is complete, the next button of the List Levels becomes interactable (`GetComponent ().interactable = false;`). I've made this script in order to unlock the buttons :
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
public class LevelManagerUnlocked : MonoBehaviour {
public int Level;
public int Progress;
public Image Image;
private string LevelString;
void Start () {
if (ButtonSettings.releasedLevelStatic >= Level) {
Levelunlocked ();
} else {
Levellocked ();
}
GetComponent<Button>().interactable = PlayerPrefs.GetInt("GameProgress") == Progress;
}
public void LevelSelect(string _level)
{
LevelString = _level;
SceneManager.LoadScene (LevelString);
}
void Levellocked()
{
GetComponent<Button> ().interactable = true;
Progress = 1;
Image.enabled = true;
Image.enabled = (PlayerPrefs.GetInt("GameProgress") == 1);
PlayerPrefs.Save();
}
void Levelunlocked ()
{
GetComponent<Button> ().interactable = true;
Image.enabled = false;
}
}
I don't really know why, but it doesn't work... when I restart the editor, I've to redo everything, all levels are locked. There's not a SetBool with PlayerPrefs, so I replaced it by SetInt (0=false, 1=true).
So, I want that when we restart the game, the buttons that became interactable get still interactable. I want that PlayerPrefs saves that THIS BUTTON became interactable, and it will stay interactable forever, even after restarting Unity.
I hope that I explained it correctly!! Not easy when you're French ;)...
Thanks!!