static var instance : LevelData;
function Awake ()
{
// Find itself
instance = FindObjectOfType(LevelData);
if (instance == null)
Debug.Log ("Could not locate a singleton object in the scene.");
// Retain between scenes
DontDestroyOnLoad(gameObject);
}
// Ensure that the instance is destroyed when the game is stopped in the editor.
function OnApplicationQuit() {
instance = null;
}
I’m trying to understand a JS singleton… I’ve condensed the basics down — from the unity wiki — into the above code and it works well but I have a niggling question. It has that function: OnApplicationQuit, null the instance — Isn’t that redundant? Wouldn’t it be emptied upon game quit anyway or am I missing something?