Skip to content

Instantly share code, notes, and snippets.

@ritobanrc
Created March 13, 2018 01:20
Show Gist options
  • Save ritobanrc/33fca10ebe0798746c9204a2145f86d1 to your computer and use it in GitHub Desktop.
Save ritobanrc/33fca10ebe0798746c9204a2145f86d1 to your computer and use it in GitHub Desktop.
A class that can be inherited from for singletons in Unity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Utility
{
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
public static T Instance
{
get
{
if (_instance == null)
{
_instance = GameObject.FindObjectOfType<T>();
}
return _instance;
}
}
private static T _instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment