Esempio n. 1
0
        public void TwoSingletonInstancesAreTheSameInstance()
        {
            SingletonBasic instance1 = SingletonBasic.Instance;
            SingletonBasic instance2 = SingletonBasic.Instance;

            Assert.AreSame(instance1, instance2);
        }
Esempio n. 2
0
    // Initialize the singleton instance.
    private void Awake()
    {
        // If there is not already an instance, set it to this.
        if (Instance == null)
        {
            Instance = this;
        }
        //If an instance already exists, destroy whatever this object is to enforce the singleton.
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        //DontDestroyOnLoad so that it won't be destroyed when reloading our scene.
        DontDestroyOnLoad(gameObject);
    }