private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
     }
 }
示例#2
0
 void Awake()
 {
     if (instance == null)          //Check if instance already exists
     {
         instance = this;           //if not, set instance to this
     }
     else if (instance != this)     //If instance already exists and it's not this:
     {
         Destroy(gameObject);       //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
     }
     DontDestroyOnLoad(gameObject); //Sets this to not be destroyed when reloading scene
 }