毎回シングルトンを作るのを楽にするために作ったのですがこのコードは何か問題がありますか?
using UnityEngine; public static class SingletonInstance { public static bool Instance<T>(ref T instance, T script, GameObject obj) { if (instance == null) { instance = script; Object.DontDestroyOnLoad(obj); return true; } else { Object.Destroy(obj); return false; } } }
using UnityEngine; public class program : MonoBehaviour { static public program instance; void Awake() { if (!SingletonInstance.Instance(ref instance, this, gameObject))return; //シングルトン作成時に何か処理があれば } }