how to create singleton class in c# unity code example
Example 1: unity singleton pattern
#region Singleton
void Awake()
{
if (instance == null)
{
instance = this;
}
else
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(gameObject);
}
#endregion
Example 2: how to make a singleton in unity
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
}