- Home /
Retaining Data Between Levels
Hello,
Having a bit of a problem retaining data between levels.
The game cycle is: Scene A -> Scene B -> Scene A -> Scene B ... and so on
I have a gameobject called GameSettings with DontDestroyOnLoad in the hierachy of Scene A. When the player completes the level, an int in GameSettings is incremented, and the scene moves to Scene B.
GameSettings is still there. All well and good. But when I return to Scene A, there are now two GameSetting Objects. One has 0 as the level, the other has the correct value, 1. Is there an easy way to stop GameSettings from being duplicated?
Answer by Next Beat Games · Dec 30, 2012 at 07:25 PM
Your method can work, but there is a simpler way: Use PlayerPrefs to save persistent data!
eg. In some gameplay handler script: if (playerScript.levelCompleted) PlayerPrefs.SetInt("some setting", PlayerPrefs.GetInt("some setting") + 1);
Answer by tomekkie2 · Dec 30, 2012 at 07:25 PM
Store your gamesettings in PlayerPrefs or just destroy the other GameSetting object - one with no scores - from the scene just after loading the level.
Your answer
Follow this Question
Related Questions
Saving and Loading 0 Answers
Saving scene causes "Importing small assets" dialog briefly, and freezes Unity for ~10 seconds 0 Answers
Save & Loading Variables 2 Answers
Serializing lists 0 Answers
How can I save a character during runtime using script? 3 Answers