Created
March 13, 2018 01:20
-
-
Save ritobanrc/33fca10ebe0798746c9204a2145f86d1 to your computer and use it in GitHub Desktop.
A class that can be inherited from for singletons in Unity.
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 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