IEnumerator EnemySpawner() { while (this) { spawnedPaths.RemoveAll((path) => { if (path.stillAlive()) { return(false); } else { paths.Add(path); return(true); } }); if (spawnedPaths.Count < maximumSpawnCount) { Camera cam = Camera.main; Vector2 bottomLeft = GetWorld(cam.ViewportPointToRay(new Vector3(0, 0, 0))); Vector2 topRight = GetWorld(cam.ViewportPointToRay(new Vector3(1, 1, 0))); if (paths.Count > 0) { SpawnPath chosenOne = null; Rect cameraWorldRect = new Rect(bottomLeft, topRight - bottomLeft); for (int i = 0; i < 5; i++) { SpawnPath path = paths[Random.Range(0, paths.Count)]; if (path.intersects(cameraWorldRect)) { chosenOne = path; break; } } if (chosenOne != null) { chosenOne.Summon(this); } } } yield return(new WaitForSeconds(spawnTimerDelay)); } yield return(null); }
private void CreateStationaryNPC(bool isCivilian, SpawnPath startingPath) { NPC npc; if (isCivilian) { npc = Instantiate(stationaryCivilian, startingPath.SpawnPos.position, startingPath.SpawnPos.rotation, transform); npc.startingPath = startingPath; stationaryCivs.Add(npc); } else { npc = Instantiate(stationaryGuard, startingPath.SpawnPos.position, startingPath.SpawnPos.rotation, transform); npc.startingPath = startingPath; inactiveGuards.Add(npc); } npc.gameObject.SetActive(false); }
private void CreateNPC(bool isCivilian, SpawnPath startingPath = null) { NPC npc; if (isCivilian) { Transform currentSpawn = civilianSpawnPos[Random.Range(0, civilianSpawnPos.Length)].SpawnPos; npc = Instantiate(civilian, currentSpawn.position, Quaternion.identity, transform); inactiveCivs.Add(npc); } else { npc = Instantiate(guard, startingPath.SpawnPos.position, Quaternion.identity, transform); npc.startingPath = startingPath; inactiveGuards.Add(npc); } npc.gameObject.SetActive(false); }