You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
882 B

using UnityEngine;
namespace Global {
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour {
public static T Instance;
private void Awake() {
if (Instance == null) {
Instance = this as T;
} else if (Instance != this) {
Debug.Log("Instance already exists, destroying object!");
Destroy(this);
}
}
}
public class PersistentSingleton<T> : MonoBehaviour where T : MonoBehaviour {
public static T Instance;
private void Awake() {
if (Instance == null) {
Instance = this as T;
DontDestroyOnLoad(this);
} else if (Instance != this) {
Debug.Log("Instance already exists, destroying object!");
Destroy(this);
}
}
}
}