1
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AutoMonoSingleton<T>: MonoBehaviour where T : MonoBehaviour
|
||||
{
|
||||
private static T _instance;
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_instance==null)
|
||||
{
|
||||
GameObject obj = new GameObject();
|
||||
obj.name = typeof(T).ToString();
|
||||
DontDestroyOnLoad(obj);
|
||||
_instance = obj.AddComponent<T>();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user