- Home /
How do i change my save "Total Coin" everytime i get more coins.
So, I will put the Total Coin in the main menu, and when I play for the first time, the coin I collected change the "Total Coin". And the second time I play the coin I collected is added to the save "Total Coin". and it keep doin that forever until I spend it. So basically the "Total Coin" Is like a bank. Right Now I just want to know how to add coins to the save "Total Coin".
My save and load scripts of the coin is right here: (I DID NOT USE PLAYER PREFS)
  public int CoinCount;
 
 public void Save()
     {
         BinaryFormatter BF = new BinaryFormatter();
         FileStream file = File.Create(Application.persistentDataPath + "/PlayerInfo.dat");
 
         PlayerData data = new PlayerData();
         data.coinCount = CoinCount;
         data.Highscore = HiScoreCount;
         BF.Serialize(file, data);
         file.Close();
     }
 
     public void load()
     {
         if (File.Exists(Application.persistentDataPath + "/PlayerInfo.dat"))
 
         {
             BinaryFormatter BF = new BinaryFormatter();
             FileStream file = File.Open(Application.persistentDataPath + "/PLayerInfo.dat", FileMode.Open);
             PlayerData data = (PlayerData)BF.Deserialize(file);
             file.Close();
             CoinCount = data.coinCount;
             HiScoreCount = data.Highscore;
 
 
         }
     }
 }
 
 [Serializable]
 class PlayerData
 {
     public int coinCount;
     public float Highscore;
 
Here how I am collecting the coins: (If you need them)
  void OnTriggerEnter2D(Collider2D other)
     {
         if (other.CompareTag("coins"))
         {
             ScoreManager.GetInstance().CoinCount += 1;
             other.gameObject.SetActive(false);
            
             
         }
 
     }
Really need some help.. Any help will be much appreciated.
Your answer
 
 
             Follow this Question
Related Questions
Unable to save and load the game data on android 1 Answer
Get Asset at runtime by its ID 0 Answers
Save Game loading Deserialization from disk 1 Answer
Deserializing data with XML Serializer 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                