Created
November 13, 2022 07:54
-
-
Save ricardj/16dfbad3fbf12f0a57d3c832db1e6ad8 to your computer and use it in GitHub Desktop.
Unity Monobehaviour Singleton
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 Singleton<T> : MonoBehaviour where T : Singleton<T> | |
{ | |
public static T get; | |
public void Awake() | |
{ | |
if (get == null) | |
{ | |
get = (T)this; | |
} | |
else if (get != this) | |
{ | |
Destroy(this.gameObject); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment