Created
May 1, 2014 17:03
-
-
Save rakkarage/9b807411d570bbfac457 to your computer and use it in GitHub Desktop.
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 UnityEngine; | |
namespace ca.HenrySoftware.Deko | |
{ | |
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