Can anyone tell me the simplest way to save state between application launches for a desktop application? By ‘state’ I mean a single number or high score.
PlayerPrefs is a good approach if it’s just a few values such as score.
1 Like
An example:
// actual construction of menu begins:
if (!PlayerPrefs.HasKey("save" + i)) // no save file for group [n], new game button
{
selectedSlot.newGameButton.SetActive(true);
}
else // save file found, label and display load button
{
selectedSlot.loadGameText.text = PlayerPrefs.GetString("save" + i);
selectedSlot.loadGameButton.SetActive(true);
}
I use this logic block to decide if a button is a new game button or a load game button, and if it is it names it.
To mess with it you literally just (elsewhere).
// add input field string to playerprefs save[slotIndex]
PlayerPrefs.SetString("save" + index, newGameName);
// delete the save file
PlayerPrefs.DeleteKey("save" + index);
So you’ll want to PlayerPrefs.SetInt(“score”, Score);
Isn’t Unity fun.