private IEnumerator SpawnMobs() { const int MAXMOBS = 10; List <Checkpoint> checkpoints = (List <Checkpoint>)GameManager.GetInstance().Checkpoints; while (true) { int wronglyCountedEliteMobs = 0; foreach (Mob mob in GameManager.GetInstance().GetTeam(2).GetMobTeamMembers()) { if (mob is EliteMob) { ++wronglyCountedEliteMobs; } } float checkpointCounter = checkpoints.Count / 2; foreach (Checkpoint checkpoint in checkpoints) { if (checkpoint.CheckType(this, Checkpoint.Type.FRIENDLY)) { checkpointCounter -= 0.5f; } else if (checkpoint.CheckType(this, Checkpoint.Type.HOSTILE)) { checkpointCounter += 0.5f; } } int meleeMobs = Mathf.RoundToInt(checkpointCounter * 2 / 3); for (int i = 0; i < meleeMobs; i++) { if (Team.TeamNo == 1) { if (GameManager.GetInstance().GetTeam(1).GetMercenaryTeamMembers().Count >= MAXMOBS) { break; } } else { if (GameManager.GetInstance().GetTeam(2).GetMobTeamMembers().Count >= MAXMOBS + wronglyCountedEliteMobs) { // +2 because someone didn't noticed the elitemobs are mobs break; } } GameObject mob = Team.TeamNo == 1 ? Datasheet.Mercenaries()[1] : Datasheet.Mobs()[0]; this.Spawn(mob); } int rangedMobs = Mathf.RoundToInt(checkpointCounter * 1 / 3); for (int i = 0; i < rangedMobs; i++) { if (Team.TeamNo == 1) { if (GameManager.GetInstance().GetTeam(1).GetMercenaryTeamMembers().Count >= MAXMOBS) { break; } } else { if (GameManager.GetInstance().GetTeam(2).GetMobTeamMembers().Count >= MAXMOBS + wronglyCountedEliteMobs) { // +2 because someone didn't noticed the elitemobs are mobs break; } } GameObject mob = Team.TeamNo == 1 ? Datasheet.Mercenaries()[0] : Datasheet.Mobs()[1]; this.Spawn(mob); } yield return(new WaitForSeconds(SPAWNRATE)); } }