Unity/Csharp/シングルトン
提供: 初心者エンジニアの簡易メモ
MonoBehaviourを使ったシングルトン
using System.Collections; using System.Collections.Generic; using UnityEngine; public class KomaManager : MonoBehaviour { private static KomaManager mInstance; public int x = 1; private KomaManager () { } public static KomaManager Instance { get { if (mInstance == null) { GameObject go = new GameObject("KomaManager"); mInstance = go.AddComponent<KomaManager>(); } return mInstance; } } void Start () { } void Update () { } }