From 3baa6c5d25d3e4022ec115a88143cbfd54081835 Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sat, 3 Feb 2024 23:22:55 +0100 Subject: [PATCH] Fixed spawner errors --- .../Scripts/Controller/EnemySpawner/EnemySpawner.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs b/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs index 943dfae..9b924ca 100644 --- a/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs +++ b/Assets/Scripts/Controller/EnemySpawner/EnemySpawner.cs @@ -93,12 +93,17 @@ public class NewBehaviourScript : MonoBehaviour void SpawnRandom(float difficulty) { - while (difficulty > 0.5f) // Spawn until difficulty is less than 0.5f + while (difficulty > 1f) // Spawn until difficulty is less than 0.5f { var validEnemies = enemyList.Where(x => x.Difficulty <= difficulty).ToArray(); - var enemyToSpawn = validEnemies[UnityEngine.Random.Range(0, validEnemies.Length)]; + int enemyIndex = UnityEngine.Random.Range(0, validEnemies.Length); + var enemyToSpawn = validEnemies[enemyIndex]; difficulty -= enemyToSpawn.Difficulty; - GameObject enemy = Instantiate(enemyToSpawn.prefabs[UnityEngine.Random.Range(0, enemyToSpawn.prefabs.Length)], GetRandomPointOnCircle(mainCam.transform.position, SpawnRadius), Quaternion.identity, SpawnedEnenmyHolder.transform); + + int variant = UnityEngine.Random.Range(0, enemyToSpawn.prefabs.Length); + GameObject variantToSpawn = enemyToSpawn.prefabs[variant]; + + GameObject enemy = Instantiate(variantToSpawn, GetRandomPointOnCircle(mainCam.transform.position, SpawnRadius), Quaternion.identity, SpawnedEnenmyHolder.transform); enemy.GetComponent().targets = players.Select(x => x.transform).ToArray(); }