Unity singleton game manager 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: 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 3: unity singleton

public class Example
{
public static Example Instance{get; private set;}

void Awake()
{
if(Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
} else
{
Destroy(gameObject);
}
}

}