whats the best way to carry data from scene to scene

i just wanted an opinion on what would be the best way to carry data (like a string) from 1 scene to another. i am making a mazemaker game and the mazes will be savable to a database. i need a good way to carry the selected maze to play from the maze selector to the scene that loads the maze.

Common methods for causing data to persist between scenes include:

  • Associating the data with a game object that’s been made persistent using DontDestroyOnLoad().
  • Using static variables.
  • Using the PlayerPrefs class.

If you want the game to ‘remember’ the last selected maze between runs of the program anyway, PlayerPrefs might be your best bet. Otherwise, either of the other two options should work.

i was thinking of using player prefs before posting this thread but i just wanted to see if there was a better way. thanks

Honestly, if it is a small amount of information, then playerprefs is the best solution. Fast save, fast load, love that little baby.

you could also write a simpleton class that never needs instantiation. This will allow all coded to asses it by its file name, but it will not persist through game sessions. (ie, if you close your browser and comeback later.

persistant_data.js

#pragma strict

static var i_score : int = 0;

score.js

function Start () {

persistant_data.i_score += 100; // adds 100 to i_score stored with in persistent data

}