I’ve read the docs on PlayerPrefs but do not fully understand how they work. I’ve found several posts on Unity Answers regarding similar issues but am not having much luck. So here’s the situation: When the player collects an object in a level I want this to be reflected when the player returns to the main menu screen. Or if the player beats a level I want to be able to select the next level in the main menu screen. Here is how I was going about it:
On my first script, in my level scene when I collected the collectible I put this as the last line of the script:
PlayerPrefs.SetInt("Level2Unlocked", 1);
On my second script, in my main menu scene I put this onto an empty game object :
using UnityEngine;
using System.Collections;
public class MenuButtonLock : MonoBehaviour {
public GameObject[] buttonLocks;
public GameObject[] buttonText;
void Start () {
if (PlayerPrefs.HasKey("Level2Unlocked")) {
NGUITools.SetActive(buttonLocks[0], false);
NGUITools.SetActive(buttonText[0], true);
}
}
}
Should I be putting this in it’s own function instead of Start? I am trying to understand how this all works. Hopefully someone can shed some light on PlayerPrefs.