using System.Collections; using System.Collections.Generic; using UnityEngine; public class Singleton : MonoBehaviour where T : Singleton { //Define singleton T instance pattern for the game private static T instance; public static T Instance { get { return instance; } } /// /// This method is called as the game is first Awake and /// it implements the singleton pattern into the MonoBehaviour /// scripts. /// protected virtual void Awake(){ if (instance != null && this.gameObject != null){ Destroy(this.gameObject); } else { instance = (T)this; } if (!gameObject.transform.parent){ DontDestroyOnLoad(gameObject); } } }