See the overview Reference Reference blog
Use singleton pattern is very extensive, I believe we learn design patterns before, he had come into contact with the singleton pattern.
1, singleton
Singleton in C #
public class Test
{
private static Test _instance;
public static Test Instance
{
get
{
if (_instance == null)
_instance = new Test();
return _instance;
}
}
}
In singleton Unity
public class Test : MonoBehaviour
{
public static Test Instance;
private void Awake()
{
Instance = this;
}
}