MoTaForPSVita/Assets/Scripts/Framework/MonoSingleton.cs

23 lines
516 B
C#
Raw Normal View History

using System.Collections;
2024-04-30 17:39:50 +08:00
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);
}
}
}