void OnSceneLoaded(Scene scene, LoadSceneMode mode) //special method used by the scene manager to do things when a scene is loaded { Debug.Log("OnSceneLoaded: " + scene.name); Debug.Log(mode); soundMgr.SetAudio(scene); //call to the sound manager to set the audio for the scene hubTracker.OnLevelLoad(scene); uiManager.OnLevelLoad(scene); invMgr.OnLevelLoad(scene); saveMgr.OnLevelLoad(scene); if (scene.name == "Level 1") { spawnObjs = GameObject.Find("EventSystem").GetComponent <SpawnObjectives>(); playerObject = GameObject.Find("PlayerSphere"); PausePlayer(); foreach (GameObject bot in GameObject.FindGameObjectsWithTag("Target")) { if (bot.GetComponent <AIMachine>()) { friendlyBots.Add(bot); } } if (missionName == "Defend") { structure = spawnObjs.structureInstance; } else if (missionName == "Protect") { foreach (GameObject ally in GameObject.FindGameObjectsWithTag("Target")) { if (ally.GetComponent <AIAllyMachine>()) { allyBots.Add(ally); } } } else if (missionName == "Destroy") { structure = spawnObjs.structureInstance; } else if (missionName == "Assault") { capArea = spawnObjs.capAreaInstance; } else if (missionName == "Hack") { terminal = spawnObjs.terminalInstance; } else if (missionName == "Kill") { } } if (scene.name == "HUB scene" || scene.name == "Main Menu") //if the player is in the hub { invMgr.addCurrency = true; if (missionComplete == false) //if the mission was not complete when the player returned to the hub, reset the currency earned { invMgr.addCurrency = false; } invMgr.ModifyCurrency(); //after the above code decides what the addCurrency bool should be, call to the invMgr to change the currency playerObject = null; allEnemies.Clear(); movingEnemies.Clear(); allyBots.Clear(); friendlyBots.Clear(); remainingEnemies = 0; spawns = null; exitOpen = false; missionComplete = false; } }
private void Awake() { gameManager = GameObject.Find("Persistent Object").GetComponent <GameManager>();//get reference to game manager to set the difficulty spawnObjs = GameObject.Find("EventSystem").GetComponent <SpawnObjectives>(); logD = GameObject.Find("RunningUI/Text Log/Log Panel/Content").GetComponent <DisplayLog>(); difficulty = gameManager.difficulty; if (difficulty == "Easy") //set the bool for what difficulty the mission is { easy = true; normal = false; hard = false; insane = false; } if (difficulty == "Normal") { easy = false; normal = true; hard = false; insane = false; } if (difficulty == "hard") { easy = false; normal = false; hard = true; insane = false; } if (difficulty == "Insane") { easy = false; normal = false; hard = false; insane = true; } foreach (GameObject movingBot in GameObject.FindGameObjectsWithTag("moveSpawn"))//add all moving bot spawns in the level to the list { movingBotSpawns.Add(movingBot); } foreach (GameObject turretBot in GameObject.FindGameObjectsWithTag("turretSpawn"))//add all turret spawns in the level to the list { turretBotSpawns.Add(turretBot); } foreach (GameObject reinforceSpawn in GameObject.FindGameObjectsWithTag("ReinforceSpawn"))//add all turret spawns in the level to the list { reinforceSpawns.Add(reinforceSpawn); } foreach (GameObject playerBot in GameObject.FindGameObjectsWithTag("Target"))//add the player and friendly bots to a list { if (playerBot.GetComponent <AIMachine>() || playerBot.GetComponent <PlayerShoot>() || playerBot.GetComponent <AIAllyMachine>()) { playerBots.Add(playerBot); } } if (difficulty == "Easy") //for each difficulty, spawn in the enemies based on the range of the random numbers { int randInt = Random.Range(easyBotMin, easyBotMax); int randInt1 = Random.Range(easyTurretMin, easyTurretMax); List <GameObject> usedSpawns = new List <GameObject>(); for (int i = 0; i < randInt; i++) //for bots { bool sameSpawn = false; int randomSpawn = Random.Range(0, movingBotSpawns.Count); for (int x = 0; x < usedSpawns.Count; x++) { if (movingBotSpawns[randomSpawn] == usedSpawns[x]) { sameSpawn = true; break; } } if (sameSpawn == false) { Instantiate(movingBot, movingBotSpawns[randomSpawn].transform); usedSpawns.Add(movingBotSpawns[randomSpawn]); } else { i--; } } usedSpawns.Clear(); //clear list of used spawns between enemy types for (int i = 0; i < randInt1; i++) //for turrets { bool sameSpawn = false; int randomSpawn = Random.Range(0, turretBotSpawns.Count); for (int x = 0; x < usedSpawns.Count; x++) { if (turretBotSpawns[randomSpawn] == usedSpawns[x]) { sameSpawn = true; break; } } if (sameSpawn == false) { Instantiate(turretBot, turretBotSpawns[randomSpawn].transform); usedSpawns.Add(turretBotSpawns[randomSpawn]); } else { i--; } } } if (difficulty == "Normal") { int randInt = Random.Range(normalBotMin, normalBotMax); int randInt1 = Random.Range(normalTurretMin, normalTurretMax); List <GameObject> usedSpawns = new List <GameObject>(); for (int i = 0; i < randInt; i++) //for bots { bool sameSpawn = false; int randomSpawn = Random.Range(0, movingBotSpawns.Count); for (int x = 0; x < usedSpawns.Count; x++) { if (movingBotSpawns[randomSpawn] == usedSpawns[x]) { sameSpawn = true; break; } } if (sameSpawn == false) { Instantiate(movingBot, movingBotSpawns[randomSpawn].transform); usedSpawns.Add(movingBotSpawns[randomSpawn]); } else { i--; } } usedSpawns.Clear(); //clear list of used spawns between enemy types for (int i = 0; i < randInt1; i++) //for turrets { bool sameSpawn = false; int randomSpawn = Random.Range(0, turretBotSpawns.Count); for (int x = 0; x < usedSpawns.Count; x++) { if (turretBotSpawns[randomSpawn] == usedSpawns[x]) { sameSpawn = true; break; } } if (sameSpawn == false) { Instantiate(turretBot, turretBotSpawns[randomSpawn].transform); usedSpawns.Add(turretBotSpawns[randomSpawn]); } else { i--; } } } if (difficulty == "Hard") { int randInt = Random.Range(hardBotMin, hardBotMax); int randInt1 = Random.Range(hardTurretMin, hardTurretMax); List <GameObject> usedSpawns = new List <GameObject>(); for (int i = 0; i < randInt; i++) //for bots { bool sameSpawn = false; int randomSpawn = Random.Range(0, movingBotSpawns.Count); for (int x = 0; x < usedSpawns.Count; x++) { if (movingBotSpawns[randomSpawn] == usedSpawns[x]) { sameSpawn = true; break; } } if (sameSpawn == false) { Instantiate(movingBot, movingBotSpawns[randomSpawn].transform); usedSpawns.Add(movingBotSpawns[randomSpawn]); } else { i--; } } usedSpawns.Clear(); //clear list of used spawns between enemy types for (int i = 0; i < randInt1; i++) //for turrets { bool sameSpawn = false; int randomSpawn = Random.Range(0, turretBotSpawns.Count); for (int x = 0; x < usedSpawns.Count; x++) { if (turretBotSpawns[randomSpawn] == usedSpawns[x]) { sameSpawn = true; break; } } if (sameSpawn == false) { Instantiate(turretBot, turretBotSpawns[randomSpawn].transform); usedSpawns.Add(turretBotSpawns[randomSpawn]); } else { i--; } } } if (difficulty == "Insane") { int randInt = Random.Range(insaneBotMin, insaneBotMax); int randInt1 = Random.Range(insaneTurretMin, insaneTurretMax); List <GameObject> usedSpawns = new List <GameObject>(); for (int i = 0; i < randInt; i++) //for bots { bool sameSpawn = false; int randomSpawn = Random.Range(0, movingBotSpawns.Count); for (int x = 0; x < usedSpawns.Count; x++) { if (movingBotSpawns[randomSpawn] == usedSpawns[x]) { sameSpawn = true; break; } } if (sameSpawn == false) { Instantiate(movingBot, movingBotSpawns[randomSpawn].transform); usedSpawns.Add(movingBotSpawns[randomSpawn]); } else { i--; } } usedSpawns.Clear(); //clear list of used spawns between enemy types for (int i = 0; i < randInt1; i++) //for turrets { bool sameSpawn = false; int randomSpawn = Random.Range(0, turretBotSpawns.Count); for (int x = 0; x < usedSpawns.Count; x++) { if (turretBotSpawns[randomSpawn] == usedSpawns[x]) { sameSpawn = true; break; } } if (sameSpawn == false) { Instantiate(turretBot, turretBotSpawns[randomSpawn].transform); usedSpawns.Add(turretBotSpawns[randomSpawn]); } else { i--; } } } Debug.Log("Enemy Spawning Complete"); }
private void Awake() { spawnObjs = GameObject.Find("EventSystem").GetComponent <SpawnObjectives>(); gameMgr = GameObject.Find("Persistent Object").GetComponent <GameManager>(); indicatorImage = GetComponent <Image>(); }
private void Awake() { spawnObjs = GameObject.Find("EventSystem").GetComponent <SpawnObjectives>(); }