So I’ve been having trouble understanding what’s going on in the UnlockLevel and IsLevelUnlocked methods, so I’ve been slowly going through the lecture again. It’s slowly making sense, but I’m stuck at a line in this code:
public static bool IsLevelUnlocked (int level){
int levelValue = PlayerPrefs.GetInt (LEVEL_KEY + level.ToString ());
bool isLevelUnlocked = (levelValue == 1);
if (level <= Application.levelCount - 1) {
return isLevelUnlocked;
} else {
Debug.LogError ("Trying to query Level not in build order");
return false;
}
}
Specifically this:
int levelValue = PlayerPrefs.GetInt (LEVEL_KEY + level.ToString ());
As I understand it, this is written to get the int of the current level back from the PlayerPrefs, which could be any number, but then Ben says “that gets back either 0, or nothing, or 1”. How is it just 0 or 1?
Also, am I right in thinking we write the next line to say that the bool only is true if the levelValue == 1?