Creating the SaveHandler script
Now, we create a script that allows us to call the functions that we just created from the preceding two scripts. First, we create a checkpoint system that saves game data at specific points within the game. Then, we create a way to allow the player to save their data whenever they want to. To get started, create a new script, and name it SaveHandler
.
The checkpoint system
The first way in which we create to save and load data is a checkpoint system. Checkpoints are typically areas in the game world on reaching which the game will save the player's data. Add this function to allow the checkpoint to save:
void OnTriggerEnter(Collider other) { if(other.tag == "SavePoint") { Camera.main.SendMessage("WriteToFile"); Destroy(other.gameObject); } }
This is a trigger-based method to save. When the player enters the triggered area, the game will save the player's data. Within the if
statement, you can call any of the save functions we created. You should...