Skip to content

Instantly share code, notes, and snippets.

@GarethIW
Created September 17, 2016 16:40
Show Gist options
  • Save GarethIW/4041cb70d799ba86a707b72945d8a7f2 to your computer and use it in GitHub Desktop.
Save GarethIW/4041cb70d799ba86a707b72945d8a7f2 to your computer and use it in GitHub Desktop.
public class Singleton : MonoBehavior
{
private static Singleton _instance;
public static Singleton Instance
{
get { return _instance; }
}
private void Awake()
{
if (_instance != null && _instance != this)
{
Destroy(this.gameObject);
}
else
{
_instance = this;
DontDestroyOnLoad(this.GameObject);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment