How can i make a script so that variables carry on from scene to scene? I want the xp of the player to carry on to other scenes?! I tried using LoadLevelAdditive but it messed up the levels quite a lot…Help?
PlayerPrefs is good for saving and loading data between play sessions (i.e., saved games).
When changing levels during the same play session, instead consider keeping the variables in a script on game object that will not be destroyed when loading a new level. To keep a game object from being destroyed, use DontDestroyOnLoad().
function Start() {
DontDestroyOnLoad(this.gameObject);
}
Alternatively, you can store the variables in a singleton or static class that isn’t a MonoBehaviour. Since it won’t be attached to a game object, it will never get destroyed.