コード例 #1
0
 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);
 }
コード例 #2
0
 private void Instantiate()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(this);
     }
     else if (this != Instance)
     {
         Destroy(this.gameObject);
     }
 }