Hi,
I want to create a global game object + script, which store global variables and values of game. I try create an GameObject call globalObject at the first scene and attach this function to keep it when load a new level:
DontDestroyOnLoad(globalObject)
But the problem is when I load other level, then load back to the first level, another globalObject was created.
I want to create an unique object through all game, how can I do that?
You can either create the global object in a level which is never loaded again (say level 0, which only exists to contain the global object and then load level 1, which we’ll say is the first “real” level), or you can have some code in Awake for that object which checks to see if the object already exists (using GameObject.Find, FindObjectOfType, etc.) and destroys itself if so.