Last active
August 29, 2015 14:22
-
-
Save Henry-E/cdb8010c293493caa6a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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