i have a class GameManager to all scenes
--------------
public static var lives : int; // for playes lives
public static var totalScore: int; // to sum score
public static var currentLevel int;
public static var level_SCORE = new int[3]; // 4 levels
level_SCORE[0] = 0;
level_SCORE[1] = 0;
level_SCORE[2] = 0;
level_SCORE[3] = 0;
...
--------------
at the end of level 0, i have a function to save the score,
when i load next level, all the variables are ok, but the arrays are cleared;
any idea?
(sorry my poor english)
You said you saved the score as you loaded the next level. Did you try loading (assigning) the value that you saved to the array value in the new scene/level?
//call this when the level is ended
saved_Score = level_SCORE[0]; //or however you saved it
//assign it to what you saved so you have the data in your new level
level_SCORE[0] = saved_Score;
i have 100 levels and i need all the scores of all levels,
in all scenes, Worldmap, level select, bonus …
so this will not work… thanks
Anything created by the scene is flushed on a new one. Apparently, the arrays count. You might try declaring the official way: var LEVEL_SCORE : int[]
(I think.)
The official Unity way to save data between scenes is to make a persistant game object. Make a regular script (don’t need statics,) put it in an empty gameObject in your first scene (has to be a scene that runs 1st for sure, and never repeats, or you’ll get two of them.) In Start, put: DontDestroyOnLoad(gameObject);
. That will tell it to stick around when you change scenes.