using System.Collections; using System.Collections.Generic; using UnityEngine; public abstract class MonoSingleton : MonoBehaviour where T : MonoBehaviour { public bool global=true; private static T instance; public static T Instance { get { if (instance == null) instance = FindObjectOfType(); return instance; } } void Awake() { if (global) { if (instance != null && instance != this.gameObject.GetComponent()) { Destroy(this.gameObject); return; } DontDestroyOnLoad(this.gameObject); instance = this.gameObject.GetComponent(); } this.OnStart(); } protected virtual void OnStart() { } }