public void Save() { PlayerData playerData = player.data; LevelData levelData = null; if (sceneManagment.CurrentLevelNumber() > 0) { Enemy[] enemies = enemyManager.GetActiveEnemies(); Tower[] towers = towerManager.GetActiveTowers().ToArray(); Dictionary <string, int> towerPositions = new Dictionary <string, int>(); Dictionary <string, int> enemyPositions = new Dictionary <string, int>(); foreach (Enemy enemy in enemies) { enemyPositions.Add(enemy.transform.position.ToString(), (int)enemy.type); } foreach (Tower tower in towers) { towerPositions.Add(tower.transform.position.ToString(), (int)tower.type); } levelData = new LevelData(sceneManagment.CurrentLevelNumber(), towerPositions, enemyPositions, Round, enemyManager.SpawnRate.ToString(), player.Coins, player.Health); } saveData.playerData = playerData; saveData.levelData = levelData; saveAndLoad.SaveGameData(saveData); }