Skip to content

Instantly share code, notes, and snippets.

@setchi
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save setchi/e579a9dadd4bf2a094fb to your computer and use it in GitHub Desktop.
Save setchi/e579a9dadd4bf2a094fb to your computer and use it in GitHub Desktop.
Scene上に配置不要のシングルトンGameObject
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