19 lines
297 B
C#
19 lines
297 B
C#
using UnityEngine;
|
|
|
|
public class Singleton<T> : MonoBehaviour where T : Component
|
|
{
|
|
public static T Instance { get; protected set; }
|
|
|
|
public virtual void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this as T;
|
|
}
|
|
if (Instance != this)
|
|
{
|
|
Object.Destroy(base.gameObject);
|
|
}
|
|
}
|
|
}
|