BinaryFormatter.Serialize()
“EndLevel” | Sprite Renderer
“EndLevel” | “DataManagement” Script
“DataManagement” Script
- in Awake() method,
- create a function, SaveData(),
- make a BinaryFormatter to serialize the data later
- make a FileStream and File to create a path and the target file
- create a container for the save data by creating another class in the script
- put the data in it
- serialize the data with the BinaryFormatter
- Don’t Forget to close the file by using File.Close()
- create a function, LoadData(),
- make a BinaryFormatter to Deserialize the data later
- make a FileStream and File to open the target file
- Deserialize the data with the BinaryFormatter
- Don’t Forget to close the file by using File.Close()
“PlayerScore()” Script
- Create a function, CountScore()
- show the current score with Debug.Log()
- calculate the score
- update the score
- Save the Score by using SaveData() function from DataManagement Class
- show the updated Score with Debug.Log()
- in Start() function
- put LoadData() function from DataManagement Class