add: DontDestroyOnLoad on GameController
add: functions for enemy managment in GameController add: LevelController now pops enemies
This commit is contained in:
@@ -5,17 +5,31 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class GameController : MonoBehaviour
|
public class GameController : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public static GameController i;
|
||||||
public List<LevelInfo> levels;
|
public List<LevelInfo> levels;
|
||||||
|
|
||||||
|
public void Start() {
|
||||||
|
if (i) { Destroy(gameObject); return; }
|
||||||
|
i = gameObject.GetComponent<GameController>();
|
||||||
|
DontDestroyOnLoad(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dictionary<Enemy, int> PopEnemies(string sceneName) {
|
||||||
|
LevelInfo li = levels.Find(x => x.scene.name == sceneName);
|
||||||
|
Dictionary<Enemy, int> enemies = li.enemies;
|
||||||
|
li.enemies.Clear();
|
||||||
|
return enemies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddEnemyInLevel(Enemy enemy, string sceneName) {
|
||||||
|
Dictionary<Enemy, int> enemies = levels.Find(x => x.scene.name == sceneName).enemies;
|
||||||
|
if (enemies.ContainsKey(enemy)) enemies[enemy] += 1;
|
||||||
|
else enemies[enemy] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class LevelInfo {
|
public class LevelInfo {
|
||||||
public SceneAsset scene;
|
public SceneAsset scene;
|
||||||
public List<EnemyInLevel> enemies;
|
public Dictionary<Enemy, int> enemies;
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class EnemyInLevel {
|
|
||||||
public GameObject enemy;
|
|
||||||
public int count;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
public class LevelController : MonoBehaviour
|
public class LevelController : MonoBehaviour
|
||||||
{
|
{
|
||||||
public List<Transform> spawnPoints;
|
public List<Transform> spawnPoints;
|
||||||
|
|
||||||
|
public void Start() {
|
||||||
|
Dictionary<Enemy, int> enemies = GameController.i.PopEnemies(SceneManager.GetActiveScene().name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user