private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);

        SceneManager.sceneLoaded += OnSceneLoaded;

        //Find the current loaded scene and set the index if found. This happens when you load a scene in the editor and isn't the start level
        for (int i = 0; i < sceneNames.Length; i++)
        {
            if (SceneManager.GetActiveScene().name == sceneNames[i])
            {
                currentLevelIndex = i;
                break;
            }
        }
    }
Пример #2
0
 private void PrepareSingleton()
 {
     if (INSTANCE == null)
     {
         INSTANCE = this;
     }
     else
     {
         Destroy(INSTANCE.gameObject);
         INSTANCE = this;
     }
 }