Created
October 3, 2016 01:31
-
-
Save tonymtz/63c5fbb3e0abce59eb63943835549e06 to your computer and use it in GitHub Desktop.
Singleton Unity C#
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
public class MySingleton : MonoBehaviour | |
{ | |
private static MySingleton instance; | |
public static MySingleton Instance | |
{ | |
get | |
{ | |
if (instance == null) | |
{ | |
GameObject mySingletonObject = new GameObject("MySingletonObject"); | |
DontDestroyOnLoad(mySingletonObject); | |
instance = mySingletonObject.AddComponent<MySingleton>(); | |
} | |
return instance; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment