I have the following:
public class GameMaster : MonoBehaviour
{
public static GameMaster GM;
public int score;
void Awake()
{
Debug.Log("GM:" + GM);
if (GM != null)
GameObject.Destroy(GM);
else
GM = this;
DontDestroyOnLoad(this);
}
}
I attached this to a Score gameobject in each of my three levels.
Everything works okay when I am on the 1st level.
When I issue the command: Application.LoadLevel(“AverageLevel”);
It goes to the 2nd level and I see the console output that GM is not null
From the 2nd level I issue the command: Application.LoadLevel(“DifficultLevel”);
It goes to the 3rd level and now I see GM is NULL !!!
Can anyone explain why this is? It seems that I can retain the score from the 1st to the 2nd level only. When I get to the 3rd level the static object is reset.