void SpawnLevel(LevelData ld) { Debug.Log("Spawning Level"); currentPlayer = Instantiate(playerPrefab, playerPrefab.transform.position, playerPrefab.transform.rotation, this.transform); PlayerController pc = currentPlayer.GetComponent <PlayerController>(); pc.OnKillCB = OnPlayerKill; pc.OnDamageCB = OnPlayerDamage; pc.SetHealth(lastPlayerHealth); if (currentEnemies.Count != 0) { Debug.LogErrorFormat("Enemies list should be empty. Count: {0}", currentEnemies.Count); currentEnemies.Clear(); } foreach (EnemyConfig cfg in ld.enemies) { GameObject go = Instantiate(enemyPrefab, cfg.position, Quaternion.identity, this.enemyContainer); EnemyScript es = go.GetComponent <EnemyScript>(); es.ApplyConfig(cfg); es.OnKillCB = EnemyKillCB; es.SetTargetGO(currentPlayer); es.SetBulletParent(bulletContainer); currentEnemies.Add(go); } }