Created
June 22, 2014 16:10
-
-
Save AngryAnt/890f6faff7b75dc4a027 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int | |
kPreLevelScenes = 2, // Number of scenes before the first level (splash, menu, etc.) | |
kPostLevelScenes = 0; // Number of scenes after last level (score, credits, whatever) | |
const string kLevelScorePrefix = "Score for level "; | |
// ... | |
void OnLevelBeat () | |
{ | |
if (Application.loadedLevel < Application.levelCount - kPostLevelScenes - 1) | |
{ | |
Application.LoadLevel (Application.loadedLevel + 1); | |
} | |
else | |
{ | |
Debug.Log ("You win!"); | |
} | |
} | |
// ... | |
int GetScore (int level) | |
{ | |
return PlayerPrefs.GetInt (kLevelScorePrefix + level, 0); | |
} | |
void SetScore (int level, int score) | |
{ | |
PlayerPrefs.SetInt (kLevelScorePrefix + level, score); | |
} | |
int Level | |
{ | |
get | |
{ | |
return Application.loadedLevel - kPreLevelScenes; | |
} | |
} | |
// ... | |
void OnHighscoreGUI () | |
{ | |
int levelCount = Application.levelCount - kPreLevelScenes - kPostLevelScenes; | |
for (int level = 0; level < levelCount; ++level) | |
{ | |
GUILayout.Label (string.Format ( | |
"Level {0}{1}: {2}", | |
level + 1, | |
level == Level ? " (current)" : "", | |
GetScore (level) | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment