I’m building a game where after you’ve completed level 1, you unlock level2, and I’ve been doing that with PlayerPrefs and it worked a few weeks ago, but now it’s just not working. All I’ve done is use PlayerPrefs.DeleteKey a couple of times in the past to adjust a few things (DeleteKey is not in the code now).
I’ve even tried it on different computers, but it’s the same on every computer. However, other people working on the same project who’ve beaten the game on their computers months ago can play level2. It’s unlocked for them, but not for me. Keep in mind that I’ve only used PlayerPrefs.DeleteKey on my own computer while in the editor to adjust a few things.
Anyway, here is my code:
Level1EndScore script:
void Start()
{
if (VoterCollision.percentage >= goalAmount)
{
if(PlayerPrefs.HasKey("level2Active") == false)
{
firstUnlock = true;
//Later in the script, a pop-up window triggers if firstUnlock = true, and it does that every time now, as the key is never found.
}
winScreen.renderer.enabled = true;
loseScreen.renderer.enabled = false;
PlayerPrefs.SetInt("Level2Active", 2);
//I've debugged this part and it's not creating an int in PlayerPrefs
}
}
LevelSelect script:
void Start ()
{
if(PlayerPrefs.HasKey("level2Active") == true)
{
buttonLevel2.active = true;
lockLevel2.active = false;
//This isn't working. buttonLevel2 is not active and lockLevel2 is active
}
else
{
buttonLevel2.active = false;
lockLevel2.active = true;
}
}
Help is much appreciated