20 lines
454 B
C#
20 lines
454 B
C#
using UnityEngine;
|
|
|
|
public class SingletonAutoMono<T> : MonoBehaviour where T : MonoBehaviour
|
|
{
|
|
private static T instance;
|
|
|
|
public static T Instance
|
|
{
|
|
get
|
|
{
|
|
if (instance == null)
|
|
{
|
|
GameObject obj = new GameObject(typeof(T).ToString());
|
|
instance = obj.AddComponent<T>();
|
|
DontDestroyOnLoad(obj);
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
} |