20 lines
410 B
C#
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);
|
|
}
|
|
} |