Answers for "gamemanager unity resets after reloading scene"

0

gamemanager unity resets after reloading scene

You need to add DontDestroyOnLoad(gameObject); in Awake. Every time the scene loads it makes a new copy of the GameManager and resets the value making the new GameManager equal the static Instance.

void Awake()
{
     if (!Instance)
     {
          Instance = this;
          DontDestroyOnLoad(gameObject);
     }
     else
     {
          //Duplicate GameManager created every time the scene is loaded
          Destroy(gameObject);
     }
}
Posted by: Guest on April-04-2022

Code answers related to "TypeScript"

Browse Popular Code Answers by Language