using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SingletonComponent<T> : MonoBehaviour where T : MonoBehaviour
{
    private static T _instance;
    public static T Instance
    {
        get
        {
            if (_instance == null)
            {
                T ins = FindObjectOfType<T>();
                if (ins == null)
                {
                    GameObject newObj = new GameObject();
                    ins = newObj.AddComponent<T>();
                    newObj.name = typeof(T).Name;
                }
                _instance = ins;
            }
            return _instance;
        }
    }


}
