Add this Awake()
to your GameManager
script, Attach this Script to a Empty GameObject
at the starting scene of your game, it will not be destroyed till the end of the Application Cycle.
public class GameManager:MonoBehaviour
{
public static GameManager Instance {get;set;get;private set;}
void Awake()
{
if(Instance==null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
Destroy(gameObject);
}
public int variable1 = 0;
}
You can call variable using
GameManager.Instance.variable1