From 787c2329ad4b5a8fcf5d881267ce0e2b37b285ae Mon Sep 17 00:00:00 2001 From: KOSMOGOR Date: Sat, 22 Mar 2025 16:55:34 +0300 Subject: [PATCH] add: DontDestroyOnLoad on GameController add: functions for enemy managment in GameController add: LevelController now pops enemies --- Assets/Scripts/Game/GameController.cs | 28 +++++++++++++++++++------- Assets/Scripts/Game/LevelController.cs | 6 +++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Game/GameController.cs b/Assets/Scripts/Game/GameController.cs index d028331..f858589 100644 --- a/Assets/Scripts/Game/GameController.cs +++ b/Assets/Scripts/Game/GameController.cs @@ -5,17 +5,31 @@ using UnityEngine; public class GameController : MonoBehaviour { + public static GameController i; public List levels; + + public void Start() { + if (i) { Destroy(gameObject); return; } + i = gameObject.GetComponent(); + DontDestroyOnLoad(gameObject); + } + + public Dictionary PopEnemies(string sceneName) { + LevelInfo li = levels.Find(x => x.scene.name == sceneName); + Dictionary enemies = li.enemies; + li.enemies.Clear(); + return enemies; + } + + public void AddEnemyInLevel(Enemy enemy, string sceneName) { + Dictionary enemies = levels.Find(x => x.scene.name == sceneName).enemies; + if (enemies.ContainsKey(enemy)) enemies[enemy] += 1; + else enemies[enemy] = 1; + } } [Serializable] public class LevelInfo { public SceneAsset scene; - public List enemies; -} - -[Serializable] -public class EnemyInLevel { - public GameObject enemy; - public int count; + public Dictionary enemies; } diff --git a/Assets/Scripts/Game/LevelController.cs b/Assets/Scripts/Game/LevelController.cs index 20f1fd7..62115df 100644 --- a/Assets/Scripts/Game/LevelController.cs +++ b/Assets/Scripts/Game/LevelController.cs @@ -1,8 +1,12 @@ -using System; using System.Collections.Generic; using UnityEngine; +using UnityEngine.SceneManagement; public class LevelController : MonoBehaviour { public List spawnPoints; + + public void Start() { + Dictionary enemies = GameController.i.PopEnemies(SceneManager.GetActiveScene().name); + } }