Hi
I am having a problem with Singleton that I have created as
public static GameManager Instance()
{
if (_sharedManager == null)
{
Object []objects = FindObjectsOfType(typeof(GameManager));
if(objects == null || objects.Length == 0)
{
GameObject singleton = new GameObject("singleton");
_sharedManager = singleton.AddComponent<GameManager>();
_sharedManager.Initialize();
DontDestroyOnLoad(singleton);
}
else if(objects.Length == 1)
{
_sharedManager = (GameManager)objects[0];
DontDestroyOnLoad(_sharedManager.gameObject);
}
else
{
throw new System.Exception("too many GameManagers");
}
}
return _sharedManager;
}
this works perfectly well as long I am in the same scene through which first time GameManager.Instance() called, but when I switch my scene or load another level then sharedManager is still not null but two of its data members which or of type Unity.Object has value equal to null which was valid object before scene switch
Please help me what I am doing wrong
Ahsan