I have a Game manager setup which has bunch of tasks like score, changingscene, and GameManager Script
using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour {
static GameManager _instance;
public static GameManager managerInstance
{
get
{
if(_instance == null)
{
_instance = GameObject.FindGameObjectWithTag("manager").GetComponent();
//Tell unity not to destroy this object when loading a new scene!
DontDestroyOnLoad(_instance.gameObject);
}
return _instance;
}
}
void Awake()
{
if(_instance == null)
{
//If I am the first instance, make me the Singleton
_instance = this;
DontDestroyOnLoad (this);
}
else
{
//If a Singleton already exists and you find
//another reference in scene, destroy it!
if(this != _instance)
Destroy(this.gameObject);
}
}
}
Now In sceneA i have this manager placed and when i move from sceneA to sceneB the gamemanager is still there
but as i start sceneB directly i get various errors regarding object being null ( clearly the manager isnt there )
So my question is
"is it ok to use game manager object placed in multiple scene, Instantiating them when we need and make them persist if we want them to move from one scene to another ? "
isnt there any centralised process from which i can handle my game ?
It will be a problem if i attempt to start game directly in sceneB if game is Over ( sceneA is Menu and options )
how can i start game in between with persistence manager object ?
↧