private void Save(string state) { BinaryFormatter bf = new BinaryFormatter(); //ASSUMPTION: all objects using this script will have unique names FileStream file = File.Open(Application.persistentDataPath + "/" + state + gameObject.name + ".dat", FileMode.OpenOrCreate); SavingAttempt myData = new SavingAttempt(); myData.maxPuzzles = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <PuzzleTracker>().maxPuzzles; myData.puzzlesDone = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <PuzzleTracker>().puzzlesDone; myData.inventory = player.GetComponent <Interact>().inventory.GetComponent <InventoryManagement>().inventory; bf.Serialize(file, myData); file.Close(); }
public void Load(string state) { if (File.Exists(Application.persistentDataPath + "/" + state + gameObject.name + ".dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/" + state + gameObject.name + ".dat", FileMode.Open); SavingAttempt myData = (SavingAttempt)bf.Deserialize(file); GameObject.FindGameObjectWithTag("MainCamera").GetComponent <PuzzleTracker>().maxPuzzles = myData.maxPuzzles; GameObject.FindGameObjectWithTag("MainCamera").GetComponent <PuzzleTracker>().puzzlesDone = myData.puzzlesDone; player.GetComponent <Interact>().inventory.GetComponent <InventoryManagement>().inventory = myData.inventory; file.Close(); } }