Ejemplo n.º 1
0
 //Set the instance to null ondestroy
 void OnDestroy()
 {
     if (Instance == this)
     {
         Instance = null;
     }
 }
Ejemplo n.º 2
0
 void Awake()
 {
     //Check if there is already an instance of
     if (Instance == null)
     {
         //if not, set it to this.
         Instance = this;
         DontDestroyOnLoad(gameObject);
     }
     //If instance already exists:
     else if (Instance != this && Instance != null)
     {
         //Destroy this, this enforces our singleton pattern.
         Destroy(gameObject);
     }
 }