Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

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);
     }
}
 
PREVIOUS NEXT
Tagged: #gamemanager #unity #resets #reloading #scene
ADD COMMENT
Topic
Name
8+6 =