My GameStateManager class for my game I'm making with Unity. It's a bit out of hand with the amount of methods, but it was the best way to handle persistent data...
using UnityEngine;
using System.Collections;
public class GameStateManager : MonoBehaviour
{
// set up basic variables
private static GameStateManager instance;
private static string levelToLoad;
private static int lives;
private static float health;
private static int score;
private static int coins;
private static int ammo;
// set up variables for maximum stuffs
private static float maxHealth;
private static int maxAmmo;
// set up boolean values for weapons and powerup system
private static bool hasCarrotLauncher = false;
private static bool hasHandGrenades = false;
private static bool hasJetpack = false;
private static bool hasSuperJump = false;
private static bool hasSwagger = false;
// other variables
private static bool isCheckpointEnabled = false;
private static Vector3 checkPointPosition;
private static GameObject playerObj;
private static GameObject checkPointObj;
private static Vector3 startPosition;
// create the instance of the manager
public static GameStateManager Instance
{
get
{
// if an instance doesn't exist, create one
if(instance == null)
{
instance = new GameObject("GameStateManager").AddComponent<GameStateManager>();
}
return instance;
}
}
/* -----------------------------------------
* The following methods will create,
* load, or save a new instance of the
* game
* -------------------------------------- */
public void NewGame()
{
// set initial values for life, score, health
lives = 3;
score = 0;
health = 100.0f;
coins = 0;
ammo = 0;
// set max health and ammo variables
maxHealth = 100.0f;
maxAmmo = 100;
// set initial values for weapons and powerups
hasCarrotLauncher = false;
hasHandGrenades = false;
hasJetpack = false;
hasSuperJump = false;
hasSwagger = false;
// set level to load
levelToLoad = "level1";
// load first level
Application.LoadLevel(levelToLoad);
}
public void SaveGame()
{
// name of current level to save
levelToLoad = Application.loadedLevelName;
FileManager.SaveString("Level", levelToLoad);
// save lives, health and score
FileManager.SaveInt("Lives", lives);
FileManager.SaveInt("Score", score);
FileManager.SaveFloat("Health", health);
FileManager.SaveInt("Coins", coins);
FileManager.SaveInt("Ammo", ammo);
// save boolean values
FileManager.SaveBoolean("HasCarrotLauncher", hasCarrotLauncher);
FileManager.SaveBoolean("HasHandGrenades", hasHandGrenades);
FileManager.SaveBoolean("HasJetPack", hasJetpack);
FileManager.SaveBoolean("HasSuperJump", hasSuperJump);
FileManager.SaveBoolean("HasSwagger", hasSwagger);
// save position of player
FileManager.SaveVector3("PlayerPosition", startPosition);
}
public void LoadGame()
{
// get name of level to load
levelToLoad = FileManager.LoadString("Level");
// get values for lives, score, health
lives = FileManager.LoadInt("Lives");
score = FileManager.LoadInt("Score");
health = FileManager.LoadFloat("Health");
coins = FileManager.LoadInt("Coins");
ammo = FileManager.LoadInt("Ammo");
// assign maxHealth and maxAmmo
maxHealth = 200.0f;
maxAmmo = 100;
// get boolean values
hasCarrotLauncher = FileManager.LoadBoolean("HasCarrotLauncher");
hasHandGrenades = FileManager.LoadBoolean("HasHandGrenades");
hasJetpack = FileManager.LoadBoolean("HasJetPack");
hasSuperJump = FileManager.LoadBoolean("HasSuperJump");
hasSwagger = FileManager.LoadBoolean("HasSwagger");
// load player's position
startPosition = FileManager.LoadVector3("PlayerPosition");
// load the level in
Application.LoadLevel(levelToLoad);
}
/* -----------------------------------------
* The following methods will update, get
* and adjust the player's stats
* -------------------------------------- */
// update health method
public void UpdateHealth(float amount)
{
health += amount;
}
// get health methods
public float GetHealth()
{
return health;
}
public float GetMaxHealth()
{
return maxHealth;
}
// update coins method
public void UpdateCoins(int amount)
{
coins += amount;
}
public int GetCoins()
{
return coins;
}
// update ammo method (called when health is full)
public void UpdateAmmo(int amount)
{
ammo += amount;
}
public int GetAmmo()
{
return ammo;
}
// update lives method
public void UpdateLives(int amount)
{
lives += amount;
}
// get lives method
public int GetLives()
{
return lives;
}
// update score method
public void UpdateScore(int amount)
{
score += amount;
}
// get score method
public int GetScore()
{
return score;
}
// set hasCarrotLauncher
public void SetHasCarrotLauncher(bool value)
{
hasCarrotLauncher = value;
}
// see if player has the carrot launcher
public bool GetHasCarrotLauncher()
{
return hasCarrotLauncher;
}
// set hand grenades method
public void SetHasHandGrenades(bool value)
{
hasHandGrenades = value;
}
// see if player has hand grenades
public bool GetHasHandGrenades()
{
return hasHandGrenades;
}
// set jetpack method
public void SetHasJetpack(bool value)
{
hasJetpack = value;
}
// see if player has jetpack
public bool GetHasJetpack()
{
return hasJetpack;
}
// set superjump method
public void SetHasSuperJump(bool value)
{
hasSuperJump = value;
}
// see if player has superjump
public bool GetHasSuperJump()
{
return hasSuperJump;
}
// set swagger method
public void SetHasSwagger(bool value)
{
hasSwagger = value;
}
// see if player has swagger
public bool GetHasSwagger()
{
return hasSwagger;
}
// set checkpoint method
public void SetCheckpointEnabled(bool value)
{
isCheckpointEnabled = value;
}
// see if checkpoint is enabled
public bool GetCheckpointEnabled()
{
return isCheckpointEnabled;
}
// set checkpoint position
public void SetCheckpointPosition(Vector3 position)
{
checkPointPosition = position;
}
// see what checkpoint position is
public Vector3 GetCheckpointPosition()
{
return checkPointPosition;
}
// set player's start position
public void SetStartPosition(Vector3 position)
{
startPosition = position;
}
// get status of start position
public Vector3 GetStartPosition()
{
return startPosition;
}
/* ----------------------------------------
* the following methods control what
* happens when the player dies and
* respawns
* ------------------------------------- */
public void FindPlayer()
{
playerObj = GameObject.FindWithTag("Player");
}
public void FindCheckpoint()
{
checkPointObj = GameObject.FindWithTag("Checkpoint");
}
public void KillPlayer()
{
// find the player
if(playerObj == null)
FindPlayer();
// player loses a life
UpdateLives(-1);
// see if player will respawn at start or checkpoint
if(GetCheckpointEnabled() == true)
{
FindCheckpoint();
playerObj.transform.position = GetCheckpointPosition();
}else
{
playerObj.transform.position = startPosition;
}
}
}
Still, looks kind of a big mess, doesn't it?

Meh game development blaugh!