Skip to content

Instantly share code, notes, and snippets.

@Henry-E
Last active August 29, 2015 14:22
Show Gist options
  • Save Henry-E/cdb8010c293493caa6a7 to your computer and use it in GitHub Desktop.
Save Henry-E/cdb8010c293493caa6a7 to your computer and use it in GitHub Desktop.
public class GameManager : MonoBehaviour
{
public static GameManager instance = null;
void Awake()
{
//Check if instance already exists
if (instance == null)
//if not, set instance to this
instance = this;
//If instance already exists and it's not this:
else if (instance != this)
//Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
Destroy(gameObject);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment