Fixed spawner errors

This commit is contained in:
BOT Alex 2024-02-03 23:22:55 +01:00
parent f5bea512ef
commit 3baa6c5d25
1 changed files with 8 additions and 3 deletions

View File

@ -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<EnemyPathFinding>().targets = players.Select(x => x.transform).ToArray();
}