// Update is called once per frame void Update() { if (player == null) { return; } currentUpgradeTime += Time.deltaTime; currentSpawnTime += Time.deltaTime; if (currentUpgradeTime > actualUpgradeTime) { if (!spawnedUpgrade) { int randomNumber = Random.Range(0, spawnPoints.Length - 1); GameObject spawnLocation = spawnPoints[randomNumber]; GameObject upgrade = Instantiate(upgradePrefab) as GameObject; Upgrade upgradeScript = upgrade.GetComponent <Upgrade>(); upgradeScript.gun = gun; upgrade.transform.position = spawnLocation.transform.position; spawnedUpgrade = true; SoundManager.Instance.PlayOneShot(SoundManager.Instance.powerUpAppear); } } if (currentSpawnTime > generatedSpawnTime) { currentSpawnTime = 0; generatedSpawnTime = Random.Range(minSpawnTime, maxSpawnTime); if (aliensPerSpawn > 0 && aliensOnScreen < totalAliens) { List <int> previousSpawnLocations = new List <int>(); if (aliensPerSpawn > spawnPoints.Length) { aliensPerSpawn = spawnPoints.Length - 1; } aliensPerSpawn = (aliensPerSpawn > totalAliens) ? aliensPerSpawn - totalAliens : aliensPerSpawn; for (int i = 0; i < aliensPerSpawn; i++) { if (aliensOnScreen < maxAliensOnScreen) { aliensOnScreen += 1; int spawnPoint = -1; while (spawnPoint == -1) { int randomNumber = Random.Range(0, spawnPoints.Length - 1); if (!previousSpawnLocations.Contains(randomNumber)) { previousSpawnLocations.Add(randomNumber); spawnPoint = randomNumber; } } GameObject spawnLocation = spawnPoints[spawnPoint]; GameObject newAlien = Instantiate(alien) as GameObject; newAlien.transform.position = spawnLocation.transform.position; Eagle alienScript = newAlien.GetComponent <Eagle>(); alienScript.target = player.transform; Vector3 targetRotation = new Vector3(player.transform.position.x, newAlien.transform.position.y, player.transform.position.z); newAlien.transform.LookAt(targetRotation); alienScript.OnDestroy.AddListener(AlienDestroyed); alienScript.GetDeathParticles().SetDeathFloor(deathFloor); } } } } }