unity make a singleton code example
Example 1: singleton unity
public class Example
{
public static Example Instance{get; private set;}
void awake()
{
if(Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
} else
{
Destroy(gameObject);
}
}
}
Example 2: unity singleton
public class Example
{
public static Example Instance{get; private set;}
void Awake()
{
if(Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
} else
{
Destroy(gameObject);
}
}
}