Game Development Reference
In-Depth Information
068 private static LoadSaveManager statemanager = null;
069
070 //Should load from save game state on level load, or just restart level from defaults
071 private static bool bShouldLoad = false;
072
073 //public variables
074 //--------------------------------------------------------------
075 //Can game accept user input?
076 private bool bInputAllowed = true;
077 //--------------------------------------------------------------
078 // Called before Start on object creation
079 void Awake ()
080 {
081 //Check if there is an existing instance of this object
082 if((instance) && (instance.GetInstanceID() != GetInstanceID()))
083 DestroyImmediate(gameObject); //Delete duplicate
084 else
085 {
086 instance = this; //Make this object the only instance
087 DontDestroyOnLoad (gameObject); //Set as do not destroy
088 }
089 }
090 //--------------------------------------------------------------
091 // Use this for initialization
092 void Start ()
093 {
094 //Add cash collected listener to listen for win condition
095 Notifications.AddListener(this, "CashCollected");
096
097 //Add game menu listeners
098 Notifications.AddListener(this, "RestartGame");
099 Notifications.AddListener(this, "ExitGame");
100 Notifications.AddListener(this, "SaveGame");
101 Notifications.AddListener(this, "LoadGame");
102
103 //If we need to load level
104 if(bShouldLoad)
105 {
106 StateManager.Load(Application.persistentDataPath + "/SaveGame.xml");
107 bShouldLoad=false; //Reset load flag
108 }
109 }
110 //--------------------------------------------------------------
111 //Function called when all cash is collected in level
112 public void CashCollected(Component Sender)
113 {
114 //Disable input
115 InputAllowed = false;
116
117 //Pause game
118 Time.timeScale = 0;
119
Search WWH ::




Custom Search