Last active
August 29, 2015 14:14
-
-
Save setchi/e579a9dadd4bf2a094fb to your computer and use it in GitHub Desktop.
Scene上に配置不要のシングルトンGameObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class SingletonGameObject<T> : MonoBehaviour where T : MonoBehaviour { | |
static T instance_; | |
public static T Instance { | |
get { | |
if (instance_ == null) { | |
instance_ = FindObjectOfType<T>(); | |
} | |
return instance_ ?? new GameObject(typeof(T).FullName).AddComponent<T>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment