title: Need help in serialization
body: <p>Been spending my last two hours trying to learn how to serialize my data i need a code that serializes my data in "StatContainer" i tried this :</p>
  
  <p><a href="https://gamedevelopment.tutsplus.com/tutorials/how-to-save-and-load-your-players-progress-in-unity--cms-20934" rel="nofollow noreferrer">https://gamedevelopment.tutsplus.com/tutorials/how-to-save-and-load-your-players-progress-in-unity--cms-20934</a> </p>
  
  <p>and alot more but i wasnt able to understand how to serialize my data</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class Stats : MonoBehaviour 
  {
      StatContainer stats = new StatContainer();
  
      // Use this for initialization
      void Start () {
          InvokeRepeating ("AddCoins", 4.0f, 2.0f);
          InvokeRepeating ("AddScore", 1.5f, 1.5f);
      }
  
      // Update is called once per frame
      void Update () {
          this.stats.Update();
      }
  
      void AddCoins (){       
          if (BunnyScript.BunnyAlive == true) {
              StatContainer.coins += 1;    
          }
      }
  
      void AddScore (){
          if (BunnyScript.BunnyAlive == true) {
              StatContainer.score += 1;
          }
      }
      }
      [System.Serializable]
      public class StatContainer
      {
      public static int coins = 0;
      public static int totalcoins = 0;
      public static int score = 0;
  
      public static int personalbest = 0;
      public static float UmbrellaSpeed = 0.1f;
      public static float currentumbdur = 500;
  
      public static int CarrotSpawnRateLVL = 1;
      public static float CarrotSpawnRate = 60f;
      public static int CarrotSpawnRateUpgradeCost = 15;
  
  
      public static int UmbrellaDurabilityLVL = 1;
      public static float UmbrellaDurability = 500;
      public static int UmbrellaDurabilityUpgradeCost = 30;
  
      public static int UmbrellaSizeLVL = 1;
      public static float UmbrellaSize = 0f;
      public static int UmbrellaSizeUpgradeCost = 25;
  
  
      public static int CarrotEffectLVL = 1;
      public static float CarrotEffect = 20;
      public static int CarrotEffectUpgradeCost = 25;
  
  
      public static int HealthRegenLVL = 1;
      public static float HealthRegenTime = 4f;
      public static int HealthRegenCost = 100;
  
  
      public static int BuyTreesCost = 250;
  
      public static int Tree1Bought = 0;
      public static float Tree1Size = 0;
      public static int Tree1SizeLVL = 1;
      public static int Tree1SizeUpgradeCost = 50;
  
      public static int Tree2Bought = 0;
      public static float Tree2Size = 0;
      public static int Tree2SizeLVL = 1;
      public static int Tree2SizeUpgradeCost = 50;
  
      public static int Tree3Bought = 0;
      public static float Tree3Size =0;
      public static int Tree3SizeLVL = 1;
      public static int Tree3SizeUpgradeCost = 50;
      // and the rest
  
      public void Update(){
          if (score &gt; personalbest) {
              personalbest = score;
          }
      }
  }
  </code></pre>
  
  <p>this is how i try to serialize it</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using System.Collections.Generic; 
  using System.Runtime.Serialization.Formatters.Binary; 
  using System.IO;
  
  public static class SaveLoad {
      public static List&lt;StatContainer&gt; savedGames = new List&lt;StatContainer&gt;();
  
      //it's static so we can call it from anywhere
      public static void Save() {
          SaveLoad.savedGames.Add(StatContainer.current);
          BinaryFormatter bf = new BinaryFormatter();
          //Application.persistentDataPath is a string, so if you wanted you can put that into debug.log if you want to know where save games are located
          FileStream file = File.Create (Application.persistentDataPath + "/savedGames.gd"); //you can call it anything you want
          bf.Serialize(file, SaveLoad.savedGames);
          file.Close();
      }   
  
      public static void Load() {
          if(File.Exists(Application.persistentDataPath + "/savedGames.gd")) {
              BinaryFormatter bf = new BinaryFormatter();
              FileStream file = File.Open(Application.persistentDataPath + "/savedGames.gd", FileMode.Open);
              SaveLoad.savedGames = (List&lt;StatContainer&gt;)bf.Deserialize(file);
              file.Close();
          }
      }
  }
  </code></pre>
  
  <p>i am calling the load fuction in the beggining of the game and the save using invoke repeating every 2 sec</p>