O'Reilly logo

Unity Game Development Scripting by Kyle D'Aoust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required