This script saves the player's transform values when the game is exited and loads the transform values on start.
When saving a transform with ESave, only the position, rotation, and scale properties are saved.
usingUnityEngine;usingEsper.ESave;publicclassSaveLoadExample:MonoBehaviour{ // Const data IDprivateconststring playerTransformDataKey ="PlayerTransform"; [SerializeField]privateTransform playerTransform;privateSaveFileSetup saveFileSetup;privateSaveFile saveFile;privatevoidStart() { // Get save file component attached to this object saveFileSetup =GetComponent<SaveFileSetup>(); saveFile =saveFileSetup.GetSaveFile(); // Load gameLoadGame(); } /// <summary> /// Loads the game. /// </summary>publicvoidLoadGame() { // Check if the data exists in the fileif (saveFile.HasData(playerPositionDataKey)) { // Get Vector3 from a special method because Vector3 is not savable datavar savableTransform =saveFile.GetTransform(playerPositionDataKey);playerTransform.CopyTransformValues(savableTransform); }Debug.Log("Loaded game."); } /// <summary> /// Saves the game. /// </summary>publicvoidSaveGame() {saveFile.AddOrUpdateData(playerPositionDataKey, playerTransform);saveFile.Save();Debug.Log("Saved game."); }privatevoidOnApplicationQuit() {SaveGame(); }}