Sharing global data among different scenes

· 1 min read

Global data can help us to share data or variables among different classes, even in different scenes.  Used scenarios such as game options including music volume, selected character's skin and so on.

It is always a good approach to have global variables in one place:

public static class GameSettings {

	// Max number of lifes that our character can have
	public static readonly int LIVES = 3;

	// Music level
	public static float musicVolume = 50.0;

Then in other scene class file, we can use the above variable:

if (currentLifes == GameSettings.LIVES) {
	// do some logic here