public void LoadGame() { if (File.Exists(Application.persistentDataPath + "/player.sav")) { FileStream fs = new FileStream(Application.persistentDataPath + "/player.sav", FileMode.Open); gameDataHash = null; // Open the file containing the data that we want to deserialize. try { BinaryFormatter formatter = new BinaryFormatter(); // Deserialize the hashtable from the file and // assign the reference to the local variable. gameDataHash = (Hashtable)formatter.Deserialize(fs); } catch (SerializationException e) { Console.WriteLine("Failed to deserialize. Reason: " + e.Message); throw; } finally { fs.Close(); } //Set the notepad to what it was saved as string notePad = (string)gameDataHash["notepad"]; notepadPanel.notepadTextField.text = notePad; string roomData = (string)gameDataHash["room"]; roomNavigation.currentRoom = controller.roomNavigation.SearchForRoom(roomData); //if text is scrolling when the game is loaded, we want it to just complete so that the new room's description can be displayed. if (AnimatedDialogueText.textIsAnimating) { controller.textAnimator.CompleteAnimateText(); } //teleport player to saved room, deleting the logs of whatever's previously been typed. controller.currentDisplayText.text = null; roomNavigation.ChangeRooms(); controller.DisplayLoggedText(); } }
void Start() { roomNavigation.ChangeRooms(); DisplayLoggedText(); }