private void updateSpawnTable() { if (worldSpawns != null && worldSpawns.StarterTable != null) { completeSpawnTable.AddRange(worldSpawns.getTable(stage)); } }
public GameObject spawnNewEnemy(LevelStage diff, float time) { if (diff != lastSpawnStage) { lastSpawnStage = diff; if (spawnTable != null) { completeSpawnTable.AddRange(spawnTable.getTable(diff)); } } if (cooldownCounter >= spawnCooldown && completeSpawnTable.Count > 0 && spawnedEnemies.Count < maxEnemies) { cooldownCounter = 0; int randIndex = Random.Range(0, completeSpawnTable.Count); if (diff == LevelStage.Medium) { randIndex = Random.Range(randIndex, completeSpawnTable.Count); } if (diff == LevelStage.VeryHard) { randIndex = Random.Range(randIndex, completeSpawnTable.Count); } SpawnTableDetails entry = completeSpawnTable[randIndex]; GameObject newEnemy = Instantiate(entry.enemyType, transform.position, transform.rotation); Enemy enClass = newEnemy.GetComponent <Enemy>(); enClass.stats = calcStats(entry.maxStats, diff, time); float hue = (360 * enClass.stats.maxHealth / entry.maxStats.maxHealth) + 60; if (hue > 360) { hue = 0; } float sat = enClass.stats.maxHealth == entry.maxStats.minHealth ? 0 : 100; if (newEnemy.name.StartsWith("GroundEnemy")) { newEnemy.GetComponentInChildren <Renderer>().materials[1].color = Color.HSVToRGB(hue / 360, sat / 100, 1); } else { newEnemy.GetComponentInChildren <Renderer>().material.color = Color.HSVToRGB(hue / 360, sat / 100, 1); } spawnedEnemies.Add(newEnemy); Instantiate(particleEffect, transform.position, transform.rotation); return(newEnemy); } else { return(null); } }