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