Souljack/Assets/_Project/Scripts/Utilities/MonoSingleton.cs

20 lines
459 B
C#

using UnityEngine;
namespace _Project.Scripts.Utilities
{
public abstract class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
{
public static T Instance { get; private set; }
protected virtual void Awake()
{
if (Instance != null&& Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this as T;
}
}
}