I have a dontdestroyonload (this) on my gui text so it carries my score to the next screen (score scene) after the timer reaches 0. from that scene (score scene) i have a button which takes me back to the main menu but the gui text with the dontdestroyonload script stays around. how can i make it so the gui text only stays for the next scene and how to i set my score system back to 0?
maybe :
function Awake() {
DontDestroyOnLoad (transform.gameObject);
}
private var keepObjectOnLevelLoad : boolean;
function OnLevelWasLoaded (level : int) {
if (!keepObjectOnLevelLoad) {
Destroy(transform.gameObject);
}
}
function KeepObject (b : boolean) {
keepObjectOnLevelLoad = b;
}
It might be possible to use the PlayerPrefs instead, to carry over settings from one scene to another, and have that GUIText object locally in each scene, without the need for DontDestroyOnLoad().
We had several troubles with DontDestroyOnLoad(), even when using the Singleton pattern for our Game Manager, since sometimes it did not find itself in the scene: Sometimes, Awake() claims gameObject.active to be true, but the GameObject.FindGameObjectsWithTag does not always find this GO, because its active-Flag is set to false during scene load until loading is finished. This is without async loading.