MoTaForPSVita/Assets/Scripts/Framework/MonoSingleton.cs
2024-04-30 17:39:50 +08:00

23 lines
519 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
{
protected static T _instance = null;
public static T Instance { get => _instance; private set => _instance = value; }
protected void Awake()
{
if (Instance == null)
{
Instance = (T)this;
//DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
}