Skip to main content
added 8 characters in body
Source Link
Rajas
  • 174
  • 1
  • 5

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

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;}
    void Awake()
    {
        if(Instance==null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
            Destroy(gameObject);
    }

    public int variable1 = 0;
}

You can call variable using

GameManager.Instance.variable1

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;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
typo
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342

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;}
    void Awake()
    {
        if(Instance==null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
            destroyDestroy(gameObject);
    }

    public int variable1 = 0;
}

You can call variable using

GameManager.Instance.variable1

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;}
    void Awake()
    {
        if(Instance==null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
            destroy(gameObject);
    }

    public int variable1 = 0;
}

You can call variable using

GameManager.Instance.variable1

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;}
    void Awake()
    {
        if(Instance==null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
            Destroy(gameObject);
    }

    public int variable1 = 0;
}

You can call variable using

GameManager.Instance.variable1
Source Link
Rajas
  • 174
  • 1
  • 5

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;}
    void Awake()
    {
        if(Instance==null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
            destroy(gameObject);
    }

    public int variable1 = 0;
}

You can call variable using

GameManager.Instance.variable1