I am making a simple Pong game on IPhone. I have made a Singleton GameManager, which keeps references to the Score text, Game over panel and the ball. Whenever I reload my scene, all of those references are missing. How do I keep those gameobject references after reload?
private void Start(){
DontDestroyOnLoad(gameObject);
}
// or JS
private function Start(){
DontDestroyOnLoad(gameObject);
}
or that may be better…
private bool IsDontDestroy=false;
private void Start(){
IsDontDestroy = true;
}
private void OnLevelWasLoaded(int level){
if(!IsDontDestroy)
Destroy(gameObject);
}
private void DisableDontDestroy(){
IsDontDestroy = false;
}
or JS
private var IsDontDestroy=false;
private function Start(){
IsDontDestroy = true;
}
private function OnLevelWasLoaded(var level){
if(!IsDontDestroy)
Destroy(gameObject);
}
private function DisableDontDestroy(){
IsDontDestroy = false;
}
What if I want those objects become destroyable after load? How do I Undo DontDestroyOnLoad?