In my game on Unity I have save/load mechanism. Here how I save the game:
// class with the all data, which need to be saved
[Serializable]
public class Saves : ScriptableObject
{
public string dateTime;
public int latestSaveSlot;
public int actNumber;
public string sceneName;
public int currentActiveSlot;
}
// method in another class, which save data
public void ButtonSave()
{
latestSaveSlot = currentActiveSlot;
saves.dateTime = System.DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
saves.latestSaveSlot = latestSaveSlot;
saves.actNumber = gameManagerScript.currentActNumber;
saves.sceneName = SceneManager.GetActiveScene().name;
var serializedSave = JsonUtility.ToJson(saves);
var saveFileName = Application.persistentDataPath + "/Save_" + currentActiveSlot + ".save";
File.WriteAllText(saveFileName, serializedSave);
}
And now I need to load it. I have 6 save slots. I need something like this:
currentActNumber = saves.actNumber + currentActiveSlot;
.. to load data from the slot I need, but without editing value of the variable.