Answer the question
In order to leave comments, you need to log in
How to load save once?
Faced a problem. I made a save through PlayerPrefs, in which it is saved in onapplicationquit, and loaded in awake. And this script is attached to the menu, and in the same script there are methods for increasing these values (did a type of statistics). but here's the problem, when i exit the level back to the menu, it loads the save again...
private static int points;
private static int enemys;
private static int asteroids;
private static int shields;
private static int asteroidsLose;
private Saver sv = new Saver();
void Awake()
{
if (PlayerPrefs.HasKey("SV"))
{
sv = JsonUtility.FromJson<Saver>(PlayerPrefs.GetString("SV"));
points = sv.points;
enemys = sv.enemys;
asteroids = sv.asteroids;
shields = sv.shields;
asteroidsLose = sv.asteroidsLose;
}
else Debug.Log("Сохранения нет");
}
void Start()
{
}
void Update()
{
}
private void OnApplicationQuit()
{
sv.points = points;
sv.enemys = enemys;
sv.asteroids = asteroids;
sv.shields = shields;
sv.asteroidsLose = asteroidsLose;
PlayerPrefs.SetString("SV", JsonUtility.ToJson(sv));
}
[Serializable]
public class Saver
{
public int points;
public int enemys;
public int asteroids;
public int shields;
public int asteroidsLose;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question