Last active
April 22, 2020 16:42
-
-
Save Dssdiego/9126e6d3a9a6da9576afd69c25b4ee8b to your computer and use it in GitHub Desktop.
Unity Singleton Pattern
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
using System; | |
using UnityEngine; | |
public class MyScript : MonoBehaviour | |
{ | |
public static MyScript Instance { get; private set; } | |
private void Awake() | |
{ | |
if (Instance != null) | |
{ | |
Destroy(this); | |
} | |
else | |
{ | |
Instance = this; | |
} | |
DontDestroyOnLoad(Instance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment