Skip to content

Instantly share code, notes, and snippets.

@Magnagames
Created July 4, 2016 21:47
Show Gist options
  • Save Magnagames/978873aa17e987cbadaac7231c6fbf71 to your computer and use it in GitHub Desktop.
Save Magnagames/978873aa17e987cbadaac7231c6fbf71 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class SingletonMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour
{
private static T instance;
public static T Instance {
get {
if (instance == null) {
instance = (T)FindObjectOfType(typeof(T));
if (instance == null) {
Debug.LogError (typeof(T) + "is nothing");
}
}
return instance;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment