title: Saving/loading Unity3d
body: <p>I'm trying to save the game everytime the player reaches a portal and then when the game is stopped and when player wants to play again he can press the continue button on the startmenu to start at the level he last unlocked.</p>
  
  <p>here is the tutorial:
  <a href="http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading" rel="nofollow">http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading</a></p>
  
  <p>here is one of the scripts on the portal that should save the game:</p>
  
  <pre><code>    using UnityEngine;
  using System.Collections;
  using System;
  using System.Runtime.Serialization.Formatters.Binary;
  using System.IO;
  
  public class Saving : MonoBehaviour
  {
  
      void OnTriggerEnter( Collider other)
      {
          if(other.gameObject.tag == "Player")
          {
              GameControl.control.levelcount += 1;
              GameControl.control.Save();
          }
      }
  }
  </code></pre>
  
  <p>gives no errors.</p>
  
  <p>here is the script for the continue button:</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using System;
  using System.Runtime.Serialization.Formatters.Binary;
  using System.IO;
  
  public class ContinueCS : MonoBehaviour {
  
      void OnMouseUp(){
          GameControl.control.Load();
          int levelcount =  GameControl.control.levelcount;
          if(levelcount == 0)
          {
              Application.LoadLevel("Level1");
          }
          else
          Application.LoadLevel(levelcount);
      }
  }
  </code></pre>
  
  <p>no errors</p>
  
  <p>and here is the script based on the tutorial:</p>
  
  <pre><code>    using UnityEngine;
  using System.Collections;
  using System;
  using System.Runtime.Serialization.Formatters.Binary;
  using System.IO;
  
       public class GameControl : MonoBehaviour {
      public static GameControl control;
  
      public float score;
      public int levelcount;
  
      void Awake () {
          if(control == null)
          {
              DontDestroyOnLoad(gameObject);
              control = this;
          }
          else if(control != this)
          {
              Destroy(gameObject);
          }
      }
  
      public void Save()
      {
          BinaryFormatter bf = new BinaryFormatter();
          FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat");
  
          PlayerData data = new PlayerData();
          data.score = score;
          data.levelcount = levelcount;
  
          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();
  
              score = data.score;
              levelcount = data.levelcount;
  
          }
      }
  }
  [Serializable]
  class PlayerData
  {
      public float score;
      public int levelcount;
  }
  </code></pre>
  
  <p>Edited!: these are the current scripts, still failing to load the last unlocked level, keeps loading level 1 and if i remove the if statement from continuescript leaving this:</p>
  
  <pre><code>void OnMouseUp(){
          GameControl.control.Load();
          int levelcount =  GameControl.control.levelcount;
          Application.LoadLevel(levelcount);
  
  
  it simply does nothing so i'm guessing the levelcount just isn't adding up.
  </code></pre>
  
  <p>i started using GameControl.control.x because in the tutorial this worked to load, save or add to variables. the only difference is that everything there is done with guibuttons. control is static so GameControl.control.levelcount +=1; should work right?</p>