Exemple #1
0
 public void LoadGame()
 {
     // 1
     if (File.Exists(Application.persistentDataPath + "/gamesave.save"))
     {
         // 2
         BinaryFormatter bf   = new BinaryFormatter();
         FileStream      file = File.Open(Application.persistentDataPath + "/gamesave.save", FileMode.Open);
         CurrentSave = (Save)bf.Deserialize(file);
         file.Close();
         SceneManager.LoadScene(CurrentSave.CurrentScene);
         SaveStation[] saveStations        = FindObjectsOfType <SaveStation>();
         SaveStation   saveFileSaveStation = FindObjectOfType <SaveStation>();
         foreach (SaveStation saveStation in saveStations)
         {
             if (saveStation.SaveStationID == CurrentSave.CurrentSaveStation)
             {
                 saveFileSaveStation = saveStation;
                 break;
             }
             else
             {
                 if (saveStation.SaveStationID == 0)
                 {
                     saveFileSaveStation = saveStation;
                     break;
                 }
             }
         }
         if (saveFileSaveStation != null)
         {
             spawnPos = saveFileSaveStation.transform.position + (Vector3)saveFileSaveStation.SpawnPosition;
         }
     }
 }
Exemple #2
0
        private void Start()
        {
            SaveStation[] saveStations        = FindObjectsOfType <SaveStation>();
            SaveStation   saveFileSaveStation = FindObjectOfType <SaveStation>();

            foreach (SaveStation saveStation in saveStations)
            {
                if (saveStation.SaveStationID == CurrentSave.CurrentSaveStation)
                {
                    saveFileSaveStation = saveStation;
                    break;
                }
                else
                {
                    if (saveStation.SaveStationID == 0)
                    {
                        saveFileSaveStation = saveStation;
                        break;
                    }
                }
            }
            if (saveFileSaveStation != null)
            {
                spawnPos = saveFileSaveStation.transform.position + (Vector3)saveFileSaveStation.SpawnPosition;
                OnLevelWasLoaded(0);
            }
        }