using UnityEngine;

public class SingletonMonoBehaviour<T> : MonoBehaviour where T : SingletonMonoBehaviour<T>
{
    static public T Instance { get; private set; }

    void Awake()
    {
        if (Instance == null)
        {
            Instance = (T)this;
            OnAwake();
        }
        else
        {
            //Debug.Log("1개이상의 싱글턴이 존재합니다" + gameObject.name);
            //Debug.Log("같은 함수가 들어간 싱글턴을 제거해 주세요");
            Destroy(gameObject);
        }
    }

    void Start()
    {
        if (Instance == (T)this)
        {
            OnStart();
        }
    }

    virtual protected void OnAwake()
    {

    }
    virtual protected void OnStart()
    {

    }
}