/// <summary> /// Spawns enemies when called. /// </summary> public void SpawnEnemies() { Quaternion rot = new Quaternion(0, 0, 0, 0); int spawnAmount = (int)((Mathf.Sqrt(wave) / 2) * difficulty * 3); while (spawnBudget > 0) { int point = Random.Range(0, spawnAreas.Length); float randPointX = Random.Range(spawnAreas[point].position.x + spawnAreas[point].GetComponent <Renderer>().bounds.size.x / 2, spawnAreas[point].position.x - spawnAreas[point].GetComponent <Renderer>().bounds.size.x / 2); float randPointZ = Random.Range(spawnAreas[point].position.z + spawnAreas[point].GetComponent <Renderer>().bounds.size.z / 2, spawnAreas[point].position.z - spawnAreas[point].GetComponent <Renderer>().bounds.size.z / 2); Vector3 randPoint = new Vector3(randPointX, spawnAreas[point].position.y, randPointZ); float chance = Random.Range(0, 1.0f); if (chance <= enemy1SpawnChance) { Instantiate(enemy1, randPoint, rot); statManager.ChangeCurrentEnemyCount(1); spawnBudget -= enemy1SpawnCost; } else { Instantiate(enemy2, randPoint, rot); statManager.ChangeCurrentEnemyCount(1); spawnBudget -= enemy2SpawnCost; } } }
public override void Die() { base.Die(); GetComponent <AI>().state = AI.CreatureState.Dead; if (GetComponent <EnemyWalkerAI>().navMesh != null) { GetComponent <EnemyWalkerAI>().navMesh.SetDestination(transform.position); } Debug.Log("Dropped loot."); lootDrop.DropLoot(transform); statManager.ChangeEnemiesKilled(1); statManager.ChangeCurrentEnemyCount(-1); GetComponent <SoundManager>().PlayDeathSound(); //Play death animation sequence and turn off all relevant components. animController.PlayDeath(); GetComponent <AI>().enabled = false; foreach (Collider col in GetComponents <Collider>()) { col.enabled = false; } if (GetComponent <StatsDisplay>() != null) { GetComponent <StatsDisplay>().healthDisplay.IsEnabled(false); GetComponent <StatsDisplay>().enabled = false; } //Update any stats and displays that change on character death. StartCoroutine(RemoveEntity(5)); }