I was wondering if there was a way to store the info from a previous scene and then use them in the next.
My situation is that I have a script for network stuff like connecting and starting a server that is attached to the main camera in the first scene (like a main menu). However, when the scene changes ( to the main game), the main camera is destroyed and so is the script ( i assume). How can I access those values in the previous scene? Thanks.
function Awake () {
DontDestroyOnLoad (transform.gameObject);
}
This keeps the parent objects of the script. You can attach this to the camera. But when ever you go back to main menu, the scene will load a new main camera with this script. So you want to create a seperate script to check if its created to make sure you only keep one camera. Which would go something like this…
static var stats = null;
var camera:Transform;
public class GameStatus {
function GameStatus() {
}
}
function Awake () {
if(stats == null){
Debug.Log("stats == null");
stats = new GameStatus();
Instantiate(camera);
}
}
you would want to attach that script to some object in the 'main menu'
Learn more about the Don't Destroy On Load 125[Here][1]125
[1]: http://unity3d.com/support/documentation/ScriptReference/Object.DontDestroyOnLoad.html