Skip to content

Instantly share code, notes, and snippets.

@AngryAnt
Created June 22, 2014 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngryAnt/890f6faff7b75dc4a027 to your computer and use it in GitHub Desktop.
Save AngryAnt/890f6faff7b75dc4a027 to your computer and use it in GitHub Desktop.
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