From d00ad7a542851e6a670c4f187e310cc1e02294f4 Mon Sep 17 00:00:00 2001
From: Moritz Meyerhof <moritz.meyerhof@rub.de>
Date: Thu, 15 Apr 2021 23:08:45 +0200
Subject: [PATCH] Enemys only spawnable between rounds

---
 Assets/Scripts/Store/EnemySpawnController.cs | 22 +++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/Assets/Scripts/Store/EnemySpawnController.cs b/Assets/Scripts/Store/EnemySpawnController.cs
index e9fede1..2f4a764 100644
--- a/Assets/Scripts/Store/EnemySpawnController.cs
+++ b/Assets/Scripts/Store/EnemySpawnController.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
-public class EnemySpawnController : MonoBehaviour
+public class EnemySpawnController : MonoBehaviour, IRoundCallback
 {
 
     [SerializeField] List<Opponent> enemyList;
@@ -13,6 +13,7 @@ public class EnemySpawnController : MonoBehaviour
     Dictionary<Opponent, Image> enemies = new Dictionary<Opponent, Image>();
 
     float mana;
+    bool running = false;
 
     Opponent activeSpawn;
     GameObject enemyImage;
@@ -29,6 +30,12 @@ public class EnemySpawnController : MonoBehaviour
         }
     }
 
+    private void Start()
+    {
+        RoundController.instance.roundCallbacks.Add(this);
+        OnRoundEnd();
+    }
+
     // Update is called once per frame
     void Update()
     {
@@ -70,11 +77,10 @@ public class EnemySpawnController : MonoBehaviour
     public void OnEnemyMouseDown(string enemyName)
     {
         SetEnemyToSpawnObject(enemyName);
-        if (StatsManager.instance.ModifyMana(-1 * (int)activeSpawn.enemyCost))
+        if (StatsManager.instance.ModifyMana(-1 * (int)activeSpawn.enemyCost) && !running)
         {
             dragObject.GetComponent<Image>().sprite = activeSpawn.EnemySprite;
             enemyImage = Instantiate(dragObject, GetPreviewWorldPosition(), Quaternion.identity, transform);
-            OnEnemyDrag();
         }
     }
 
@@ -109,4 +115,14 @@ public class EnemySpawnController : MonoBehaviour
         pos.z = 0;
         return pos;
     }
+
+    public void OnRoundStart()
+    {
+        running = true;
+    }
+
+    public void OnRoundEnd()
+    {
+        running = false;
+    }
 }
-- 
GitLab