Skip to content

Instantly share code, notes, and snippets.

@s2kw
Created October 14, 2014 03:06
Show Gist options
  • Save s2kw/78fb436d1fc407aa7e39 to your computer and use it in GitHub Desktop.
Save s2kw/78fb436d1fc407aa7e39 to your computer and use it in GitHub Desktop.
singleton 1
using UnityEngine;
using System.Collections;
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
protected static T instance;
public static T Instance
{
get
{
if(instance == null)
{
instance = (T) FindObjectOfType(typeof(T));
if (instance == null)
{
Debug.LogError("An instance of " + typeof(T) +
" is needed in the scene, but there is none.");
}
}
return instance;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment