using System.Collections; using System.Collections.Generic; using UnityEngine; public class SingletonGameObject : MonoBehaviour where T : Component { private static T instance; public static T Instance { get { if (instance == null) { instance = FindObjectOfType(); if (instance == null) { instance = new GameObject("SingletonGameObject").AddComponent(); } DontDestroyOnLoad(instance.gameObject); } return instance; } } }