「Unity/Csharp/シングルトン」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==MonoBehaviourを使ったシングルトン== using System.Collections; using System.Collections.Generic; using UnityEngine; public class KomaManager : MonoBehaviou...」) |
(→MonoBehaviourを使ったシングルトン) |
||
| 行10: | 行10: | ||
public static KomaManager Instance { | public static KomaManager Instance { | ||
get { | get { | ||
| − | if( mInstance == null ) { | + | if (mInstance == null) { |
GameObject go = new GameObject("KomaManager"); | GameObject go = new GameObject("KomaManager"); | ||
mInstance = go.AddComponent<KomaManager>(); | mInstance = go.AddComponent<KomaManager>(); | ||
2017年9月22日 (金) 23:51時点における版
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 () {
}
}
