gather-and-defend/Assets/Scripts/General/SingletonBehaviour.cs
2023-10-01 21:50:12 -04:00

20 lines
410 B
C#

using UnityEngine;
/// <summary>
/// a singleton but as a MonoBehaviour
/// </summary>
/// <typeparam name="T"></typeparam>
public class SingletonBehaviour<T> : MonoBehaviour where T : SingletonBehaviour<T>
{
public static T Instance
{
get;
private set;
}
protected virtual void Awake()
{
if (!Instance) Instance = this as T;
else Destroy(this);
}
}