Beispiel #1
0
    public void Save()
    {
        //we check for file
        FileStream file = null;

        try
        {
            BinaryFormatter bf = new BinaryFormatter();
            file = File.Create(Application.persistentDataPath + "GameData.dat");//here we create file to save
            if (data != null)
            {
                data.setIsGameStartedFirstTime(isGameStartedFirstTime);
                data.setIsMusicOn(isMusicOn);
                data.setHighScore(hiScore);
                bf.Serialize(file, data);
            }
        }
        catch (Exception e)
        { }
        finally
        {
            if (file != null)
            {
                file.Close();
            }
        }
    }
Beispiel #2
0
    //here we initialize our variable like score , music etc
    void InitializeVariables()
    {
        Load();
        if (data != null)
        {
            isGameStartedFirstTime = data.getIsGameStartedFirstTime();
        }
        else
        {
            isGameStartedFirstTime = true;
        }

        if (isGameStartedFirstTime)
        {
            hiScore = 0;
            isGameStartedFirstTime = false;
            isMusicOn = true;

            data = new GameData_DontTouch();

            //here we set the values of respective variables in there respective methods which we have created
            // in GameData class
            data.setIsGameStartedFirstTime(isGameStartedFirstTime);
            data.setIsMusicOn(isMusicOn);
            data.setHighScore(hiScore);

            Save();
            Load();
        }
        else
        {
            isGameStartedFirstTime = data.getIsGameStartedFirstTime();
            isMusicOn = data.getIsMusicOn();
            hiScore   = data.getHighScore();
        }
    }