public void Awake() //singlton { if (instance == null) //if instance is not assigned { instance = this.gameObject.GetComponent <DoNotDestory>(); //then assign instance to this object } else if (instance != this) { Destroy(this.gameObject); //then destroy this object } DontDestroyOnLoad(gameObject); }
private void Instantiate() { if (Instance == null) { Instance = this; DontDestroyOnLoad(this); } else if (this != Instance) { Destroy(this.gameObject); } }