void Start() { AsteroidCount = 1000; minSpeed = DDAAply.instance.getAsteroidSpeed(); if (minSpeed < 0f) { minSpeed = 0f; } maxSpeed = minSpeed + 1f; for (int i = 0; i < AsteroidCount; i++) { GameObject asteroid = (GameObject)Instantiate(asteroidPrefab, StartPosition(), Quaternion.Euler(0, 0, 0)); float scale = Random.Range(minSize, maxSize); if (scale >= 5.0f && !asteroid.GetComponent <AsteroidType>().explosive) { asteroid.GetComponent <AsteroidType>().indestructible = true; } asteroid.transform.localScale = new Vector3(scale, scale, scale); AsteroidMovement movement = GameObject.FindObjectOfType <AsteroidMovement>(); movement.Direction = AsteroidDirection(); movement.setSpeed(Random.Range(minSpeed, maxSpeed)); } }
private void SpawnAsteroid() { GameObject asteroidGO = asteroidPool.GetInstance(); Asteroid asteroid = asteroidGO.GetComponent <Asteroid>(); asteroid.onRequireDestroy += RemoveAsteroid; AsteroidMovement asteroidMovement = asteroid.GetComponent <AsteroidMovement>(); if (asteroidCount % 3 == 0) { multiplier += Time.time * Time.deltaTime * increaseSpeed; asteroidMovement.velocity = baseVelocity + baseVelocity * multiplier; } asteroidMovement.velocity = Mathf.Clamp(asteroidMovement.velocity, 0, maxSpeed); Transform asteroidT = asteroidGO.transform; asteroidT.position = spawnPosition; SetAsteroidPosition(asteroidT); asteroidGO.SetActive(true); asteroidCount++; if (asteroidCount % 15 == 0) { asteroidsToSpawn++; } }
private void OnTriggerEnter2D(Collider2D other) { if (other.ToString().Contains("Asteroid")) { gameObject.transform.position = new Vector2(15, 20); Destroy(gameObject, 0.5f); AsteroidHealth targetHealth = other.GetComponent <AsteroidHealth>(); AsteroidMovement targetSpeed = other.GetComponent <AsteroidMovement>(); if (targetHealth.getHealth() % numberValue == 0) { targetHealth.takeDamage(numberValue); } else { targetSpeed.ChangeSpeed(speedMultiplier); } } else if (other.ToString().Contains("AlienShip")) { gameObject.transform.position = new Vector2(15, 20); Destroy(gameObject, 0.5f); } else if (other.ToString().Contains("Power")) { gameObject.transform.position = new Vector2(15, 20); Destroy(gameObject, 0.5f); } }
private void SpawnAteroid() { AsteroidMovement temp = Asteroidp.GetFromPool(Random.Range(0, 3)); temp.transform.position = new Vector3(Random.Range(-5f, 5f), 0, 16); temp.gameObject.SetActive(true); }
/// <summary> /// Spawns a new level 2 asteroid /// Sets a random direction and assigns other values /// </summary> /// <param name="lvl">Lvl.</param> /// <param name="asteroid">Asteroid.</param> void Spawn(int lvl, GameObject asteroid) { // get the type of the destroyed asteroid int num = asteroid.GetComponent <AsteroidMovement> ().Type; // start at the position of the previous Vector3 pos = asteroid.transform.position; // instantiate a new asteroid GameObject temp = (GameObject)Instantiate(prefabs [num], pos, Quaternion.identity); // access the asteroid movement script on the asteroids AsteroidMovement script = temp.GetComponent <AsteroidMovement> (); AsteroidMovement ast = asteroid.GetComponent <AsteroidMovement> (); // set a new direction based off the old Vector3 dir = Quaternion.Euler(0, 0, Random.Range(-90, 91)) * ast.Direction; // set the values script.SetValues(2f, pos, dir, num, lvl); // scale the object temp.transform.localScale = temp.transform.lossyScale * 0.5f; // add it to the asteroids list asteroids.Add(temp); }
void BulletCollision() { bullets = shipShootBulletScript.bullets; if (bullets.Count > 0) { for (int i = 0; i < bullets.Count; i++) { SpriteRenderer bulletRender; if (bullets[i] != null) { bulletRender = bullets[i].GetComponent <SpriteRenderer>(); for (int j = 0; j < asteroids.Count; j++) { SpriteRenderer asteroidRender = asteroids[j].GetComponent <SpriteRenderer>(); if (detect.AABBCollision(bullets[i], asteroids[j])) { source.Play(); asteroidMovementScript = asteroids[j].GetComponent <AsteroidMovement>(); //this makes sure that the asteroid is the first so it splits if (asteroidMovementScript.firstIteration) { //creating 2 new asteroids GameObject asteroid1 = Instantiate(asteroidSpawningScript.asteroidPrefabs[Random.Range(0, asteroidSpawningScript.asteroidPrefabs.Count)], asteroids[j].transform.position, Quaternion.identity); asteroid1.transform.localScale /= 2; AsteroidMovement asteroid1Movement = asteroid1.GetComponent <AsteroidMovement>(); asteroid1Movement.asteroidVelocity = asteroids[j].GetComponent <AsteroidMovement>().asteroidVelocity *Random.Range(0.9f, 1.1f); asteroid1Movement.firstIteration = false; asteroids.Add(asteroid1); GameObject asteroid2 = Instantiate(asteroidSpawningScript.asteroidPrefabs[Random.Range(0, asteroidSpawningScript.asteroidPrefabs.Count)], asteroids[j].transform.position, Quaternion.identity); asteroid2.transform.localScale /= 2; AsteroidMovement asteroid2Movement = asteroid2.GetComponent <AsteroidMovement>(); asteroid2Movement.asteroidVelocity = asteroids[j].GetComponent <AsteroidMovement>().asteroidVelocity *Random.Range(0.9f, 1.1f); asteroid2Movement.firstIteration = false; asteroids.Add(asteroid2); } //GameObject asteroid2 = Instantiate(asteroidSpawningScript.asteroidPrefabs[asteroidSpawningScript.asteroidPrefabIndex], asteroids[j].transform.position, Quaternion.identity); Destroy(bullets[i]); bullets.RemoveAt(i); if (asteroidMovementScript.firstIteration) { score += 20; } else { score += 50; } Destroy(asteroids[j]); asteroids.RemoveAt(j); asteroidSpawningScript.asteroids = asteroids; shipShootBulletScript.bullets = bullets; break; } } } } } }
private IEnumerator SpawnHazard() { int asteroidCount = AsteroidSpawnCount; int enemyCount = EnemySpawnCount; int rand; while (true) { while (asteroidCount > 0 && enemyCount > 0) { rand = Random.Range(0, 100); Debug.Log(rand); if (rand < 65) // Asteroid { asteroidCount--; AsteroidMovement asteroid = asteroidPool.GetFromPool(Random.Range(0, 3)); asteroid.transform.position = new Vector3(Random.Range(SpawnPosXMin, SpawnPosXMax), 0, SpawnPosZ); } else // enemy { enemyCount--; EnemyController enemy = enemyPool.GetFromPool(); enemy.transform.position = new Vector3(Random.Range(SpawnPosXMin, SpawnPosXMax), 0, SpawnPosZ); } yield return(new WaitForSeconds(SpawnTime)); } if (asteroidCount > 0) { for (int i = 0; i < asteroidCount; i++) { AsteroidMovement asteroid = asteroidPool.GetFromPool(Random.Range(0, 3)); asteroid.transform.position = new Vector3(Random.Range(SpawnPosXMin, SpawnPosXMax), 0, SpawnPosZ); yield return(new WaitForSeconds(SpawnTime)); } } else { for (int i = 0; i < enemyCount; i++) { EnemyController enemy = enemyPool.GetFromPool(); enemy.transform.position = new Vector3(Random.Range(SpawnPosXMin, SpawnPosXMax), 0, SpawnPosZ); yield return(new WaitForSeconds(SpawnTime)); } } yield return(new WaitForSeconds(5)); asteroidCount = AsteroidSpawnCount; enemyCount = EnemySpawnCount; } }
private IEnumerator SpawnHazard() { WaitForSeconds PiointThree = new WaitForSeconds(0.3f); WaitForSeconds spawnRate = new WaitForSeconds(mSpawnRate); int enemyCount = 3; int astCount = 5; int CurrentEnemyCount; int CurrentAstCount; float ratio = 1f / 3; while (true) { CurrentAstCount = astCount; CurrentEnemyCount = enemyCount; while (CurrentAstCount > 0 && CurrentEnemyCount > 0) { float rand = Random.Range(0, 1f); // float rand = Random.value(0, 1f); if (rand < ratio) { Enemy enemy = mEemyPool.GetFromPool(); enemy.transform.position = new Vector3(Random.Range(mSpawnXMin, mSpawnXMax), 0, mSpawnZ); CurrentEnemyCount--; yield return(PiointThree); } else { AsteroidMovement ast = mAstPool.GetFromPool(Random.Range(0, 3)); ast.transform.position = new Vector3(Random.Range(mSpawnXMin, mSpawnXMax), 0, mSpawnZ); CurrentAstCount--; yield return(PiointThree); } } for (int i = 0; i < CurrentAstCount; i++) { AsteroidMovement ast = mAstPool.GetFromPool(Random.Range(0, 3)); ast.transform.position = new Vector3(Random.Range(mSpawnXMin, mSpawnXMax), 0, mSpawnZ); yield return(PiointThree); } for (int i = 0; i < CurrentEnemyCount; i++) { Enemy enemy = mEemyPool.GetFromPool(); enemy.transform.position = new Vector3(Random.Range(mSpawnXMin, mSpawnXMax), 0, mSpawnZ); yield return(PiointThree); } yield return(spawnRate); } }
private void Explosion() { GameData.destroyedAsteroids++; AsteroidMovement motion = gameObject.GetComponentInParent(typeof(AsteroidMovement)) as AsteroidMovement; motion.ChangeSpeed(0f); ExplosionManager explosionInstance = Instantiate(asteroidExplode, new Vector3(transform.position.x, transform.position.y, 0), Quaternion.identity) as ExplosionManager; Destroy(barInstance.gameObject, 0f); Destroy(gameObject, 0.0f); }
// Start is called before the first frame update void Start() { Debug.Log("Started CommunicatesManager"); enemyPlanet = FindObjectOfType <EnemyPlanet>(); asteroid = FindObjectOfType <AsteroidMovement>(); diff = enemyPlanet.enemyPosition - asteroid.transform.position; Debug.Log(diff); // 23 and 29 are primes, which means that they will cross on 23*29 time, it's longer than desired game // lenght (600 seconds) which means that philosophical communicates won't update at the same time as the other ones. InvokeRepeating("UpdateCommunicates", 20f, 11f); }
public AsteroidMovement GetFromPool(int index) { for (int i = 0; i < asteroidList[index].Count; i++) { if (!asteroidList[index][i].gameObject.activeInHierarchy) { return(asteroidList[index][i]); } } AsteroidMovement temp = Instantiate(asteroid[index]); asteroidList[index].Add(temp); return(temp); }
public AsteroidMovement GetFromPool(int id) { for (int i = 0; i < pool[id].Count; i++) { if (!pool[id][i].gameObject.activeInHierarchy) { pool[id][i].gameObject.SetActive(true); return(pool[id][i]); } } AsteroidMovement newObj = Instantiate(origin[id]); pool[id].Add(newObj); return(newObj); }
public AsteroidMovement GetFromPool(int id) { for (int i = 0; i < PoolArr[id].Count; i++) { if (!PoolArr[id][i].gameObject.activeInHierarchy) { PoolArr[id][i].gameObject.SetActive(true); return(PoolArr[id][i]); } } AsteroidMovement newObj = Instantiate(PrefabArr[id]); PoolArr[id].Add(newObj); return(newObj); }
public AsteroidMovement GetFromPool(int id = 0) { for (int i = 0; i < mPool[id].Count; i++) { if (!mPool[id][i].gameObject.activeInHierarchy) { mPool[id][i].gameObject.SetActive(true); return(mPool[id][i]); } } AsteroidMovement newObj = Instantiate(mOriginArr[id]); mPool[id].Add(newObj); return(newObj); }
public AsteroidMovement GetFromPool(int id) { for (int i = 0; i < Pools[id].Count; i++) { if (!Pools[id][i].gameObject.activeInHierarchy) { Pools[id][i].gameObject.SetActive(true); return(Pools[id][i]); } } AsteroidMovement newObj = Instantiate(Prefabs[id]); //instantiate는 인스턴스 생성이라는 의미를 가진다.(계층란에 새로운 으브젝트를 복제하여 만듬) Pools[id].Add(newObj); return(newObj); }
// Use this for initialization void Start() { maxNegYOffset = (layerNum - 1) * (ySpread / 2); for (int k = 0; k < layerNum; k++) { float yOffset = (-1 * maxNegYOffset) + (k * ySpread); for (int j = 0; j < asteroidsNumber.Length; j++) { for (int i = 0; i < asteroidsNumber[j]; i++) { sphereSize = radius[j]; float initSize = sphereSize / (Mathf.Sqrt(2)); x = Random.Range(-initSize, initSize); y = Random.Range(-ySpread, ySpread); // y = Random.Range(-sphereSize, sphereSize); z = Random.Range(-initSize, initSize); xRot = Random.Range(0, 360); yRot = Random.Range(0, 360); zRot = Random.Range(0, 360); size = Random.Range(minSize[j], maxSize[j]); asteroid = asteroids[Random.Range(0, asteroids.Length)]; if (asteroid != null) { Vector3 newPosition = new Vector3(x, 0, z); //direction in (set y=0, to keep asteroids in xz-layer) asteroid.transform.localScale = new Vector3(size, size, size); newPosition = newPosition.normalized * Random.Range(minRadius, radius[j]); newPosition.y = ufo.position.y + yOffset + y; //set semi-random height relative to UFO position GameObject newAsteroid = GameObject.Instantiate(asteroid, newPosition, Quaternion.Euler(xRot, yRot, zRot), gameObject.transform); AsteroidMovement move = newAsteroid.GetComponentInChildren <AsteroidMovement>(); move.moveSpeed = moveSpeed[j]; move.radius = radius[j]; move.yOffset = yOffset; // move.SetMovement(); } } } } }
private void ClosestVirus() { if (false) { AsteroidMovement closest = null; var playerPosition = _player.transform.position; foreach (var ai in asteroids) { if (closest == null) { closest = ai; } else if (Vector3.Distance(ai.transform.position, playerPosition) < Vector3.Distance(closest.transform.position, playerPosition)) { closest = ai; } } Debug.DrawLine(playerPosition, closest.transform.position, Color.red, 0.5f); } }
private void SetAsteroidMovement(SpawnPoint sp, AsteroidMovement asteroid) { float xDirection, yDirection; // Determine movement direction based on the position of the SpawnPoint switch (sp.tag) { case SpawnPoint.TOP: // Move downwards xDirection = Random.Range(-1, 1); yDirection = -1; break; case SpawnPoint.BOTTOM: // Move upwards xDirection = Random.Range(-1, 1); yDirection = 1; break; case SpawnPoint.LEFT: // Move right xDirection = 1; yDirection = Random.Range(-1, 1); break; case SpawnPoint.RIGHT: // Move left xDirection = -1; yDirection = Random.Range(-1, 1); break; default: xDirection = Random.Range(-1, 1); yDirection = Random.Range(-1, 1); break; } // Move in that direction asteroid.Move(new Vector2(xDirection, yDirection)); }
// private bool destroyed = false; // private bool split = false; // Use this for initialization void Start() { asteroid = (GameObject)Resources.Load("Assets/Astroids Assets/Prefabs/Asteroid"); //asteroids = new List<GameObject>(); spawnPoint = GameObject.FindGameObjectWithTag("SpawnPoint"); asteroid = Instantiate(asteroid,spawnPoint.transform.position, Quaternion.identity) as GameObject; astroMove = asteroid.GetComponent(typeof(AsteroidMovement)) as AsteroidMovement; astroMove.xMinVelocity = xMinVelocity; astroMove.xMaxVelocity = xMaxVelocity; astroMove.yMinVelocity = yMinVelocity; astroMove.yMaxVelocity = yMaxVelocity; //asteroid.SetActive(false); /*foreach(GameObject child in Asteroids) { CastRay(child); }*/ }
// Use this for initialization void Start() { // get the renderer sRend = gameObject.GetComponent <SpriteRenderer> (); // set the radius as the sprite's y extent shrunk a bit radius = sRend.sprite.bounds.extents.y; // set the center to the ship's position center = transform.position; // used to scale the sprite scale = transform.lossyScale; // set the asteroid movement aMove = gameObject.GetComponent <AsteroidMovement> (); // scale down the sprite for level 2 asteroids if (aMove.Level == 2) { scale = scale * 0.75f; } }
/// <summary> /// Spawns a new asteroid when there are less than 5 /// Sets a random direction and assigns other values /// </summary> void Spawn(int lvl) { // pick a random number to select a prefab int num = Random.Range(0, 3); // get a random position Vector3 pos = new Vector3(Random.Range(-14f, 15f), Random.Range(-4f, 5f), 0f); // instantiate a new asteroid GameObject temp = (GameObject)Instantiate(prefabs [num], pos, Quaternion.identity); // access the asteroid movement script on the asteroid AsteroidMovement script = temp.GetComponent <AsteroidMovement> (); // gives the asteroid a random direction Vector3 dir = Quaternion.Euler(0, 0, Random.Range(0, 360F)) * new Vector3(0, 1, 0); // set the values of the asteroid script.SetValues(1f, pos, dir, num, lvl); // add it to the asteroids list asteroids.Add(temp); }
void ShieldCollision() { asteroids = asteroidSpawningScript.asteroids; //set the asteroid list with asteroids from the spawningScript for (int i = 0; i < asteroids.Count; i++) { shieldRender = shield.GetComponent <SpriteRenderer>(); SpriteRenderer planetRender = asteroids[i].GetComponent <SpriteRenderer>(); if (detect.AABBCollision(shield, asteroids[i])) { source.Play(); asteroidMovementScript = asteroids[i].GetComponent <AsteroidMovement>(); if (asteroidMovementScript.firstIteration) { score += 20; } else { score += 50; } Destroy(asteroids[i]); //destroys the current asteroid that collided with the ship asteroids.RemoveAt(i); //remove the asteroid from the list } } }
private IEnumerator Hazards(float startTime, float stageGap) { WaitForSeconds gap = new WaitForSeconds(stageGap); WaitForSeconds spawnGap = new WaitForSeconds(.2f); yield return(new WaitForSeconds(startTime)); while (true) { int randInt = Random.Range(5, 11); int randEnem = Random.Range(3, 6); while (randInt > 0 || randEnem > 0) { if (randInt > 0 && randEnem > 0) { int val = Random.Range(0, 2); if (val == 0) { //GameObject temp = Instantiate(Asteroid[Random.Range(0, Asteroid.Length)]); AsteroidMovement temp = AsteroidP.GetFromPool(Random.Range(0, 3)); temp.gameObject.SetActive(true); float randPosX = Random.Range(-5f, 5f); temp.transform.position = new Vector3(randPosX, temp.transform.position.y, 16.5f); randInt--; } else { //GameObject temp = Instantiate(Enemy); EnemyController temp = EnemyP.GetFromPool(); temp.gameObject.SetActive(true); float randPosX = Random.Range(-5f, 5f); temp.transform.position = new Vector3(randPosX, temp.transform.position.y, 16.5f); randEnem--; } } else if (randInt <= 0) { EnemyController temp = EnemyP.GetFromPool(); temp.gameObject.SetActive(true); float randPosX = Random.Range(-5f, 5f); temp.transform.position = new Vector3(randPosX, temp.transform.position.y, 16.5f); randEnem--; } else if (randEnem <= 0) { //GameObject temp = Instantiate(Asteroid[Random.Range(0, Asteroid.Length)]); AsteroidMovement temp = AsteroidP.GetFromPool(Random.Range(0, 3)); temp.gameObject.SetActive(true); float randPosX = Random.Range(-5f, 5f); temp.transform.position = new Vector3(randPosX, temp.transform.position.y, 16.5f); randInt--; } yield return(spawnGap); } CurrentBossSpawnCount--; yield return(gap); if (CurrentBossSpawnCount <= 0) { BossController boss = BossP.GetFromPool(); boss.transform.position = new Vector3(0, boss.transform.position.y, 18.5f); boss.gameObject.SetActive(true); IsBossAlive = true; } while (IsBossAlive) { yield return(gap); } } }
private IEnumerator SpawnHazard() { WaitForSeconds PointThree = new WaitForSeconds(0.3f); WaitForSeconds spawnRate = new WaitForSeconds(mSpawnRate); int enemyCount = 3; int astCount = 5; int CurrentEnemyCount; int CurrentAstCount; int CurrentItemWaveCount = 0; float ratio = 1f / 3; while (true) { CurrentAstCount = astCount; CurrentEnemyCount = enemyCount; while (CurrentAstCount > 0 && CurrentEnemyCount > 0) { float rand = Random.Range(0, 1f); // float rand = Random.value(0, 1f); if (rand < ratio) { Enemy enemy = mEemyPool.GetFromPool(); enemy.transform.position = new Vector3(Random.Range(mSpawnXMin, mSpawnXMax), 0, mSpawnZ); CurrentEnemyCount--; yield return(PointThree); } else { AsteroidMovement ast = mAstPool.GetFromPool(Random.Range(0, 3)); ast.transform.position = new Vector3(Random.Range(mSpawnXMin, mSpawnXMax), 0, mSpawnZ); CurrentAstCount--; yield return(PointThree); } } for (int i = 0; i < CurrentAstCount; i++) { AsteroidMovement ast = mAstPool.GetFromPool(Random.Range(0, 3)); ast.transform.position = new Vector3(Random.Range(mSpawnXMin, mSpawnXMax), 0, mSpawnZ); yield return(PointThree); } for (int i = 0; i < CurrentEnemyCount; i++) { Enemy enemy = mEemyPool.GetFromPool(); enemy.transform.position = new Vector3(Random.Range(mSpawnXMin, mSpawnXMax), 0, mSpawnZ); yield return(PointThree); } if (CurrentItemWaveCount >= mItemSpawnWaveCount - 1) { Item tem = mItemPool.GetFromPool(Random.Range(0, 3)); tem.transform.position = new Vector3(Random.Range(mSpawnXMin, mSpawnXMax), 0, mSpawnZ); CurrentItemWaveCount = 0; } else { CurrentItemWaveCount++; } yield return(spawnRate); mBossAppear++; if (mBossAppear >= mSpawnCount) { mBoss.gameObject.SetActive(true); while (mBoss.IsAlive) { yield return(PointThree); } mBossAppear = 0; yield return(spawnRate); } } }
public void Start() { _mvt = gameObject.GetComponent<AsteroidMovement> (); _Value = (int)(_mvt.Speed * 9000.0f); }
private void Awake() { movement = GetComponent <AsteroidMovement>(); stats = GetComponent <AsteroidStats>(); }
private void OnTriggerEnter2D(Collider2D collision) { //If the asteroid collides with a laser if (collision.CompareTag("Laser")) { //get the required components GameObject[] player = GameObject.FindGameObjectsWithTag("Player"); PlayerMovement playerMovement = player[1].GetComponent <PlayerMovement>(); AsteroidMovement parentAsteroid = gameObject.GetComponent <AsteroidMovement>(); //play the explosion audio audio.Play(); //reduce the projectile count by 1 playerMovement.projectilesOnScreen -= 1; //add credits to the player's stats PlayerStats.instance.availableCredits += parentAsteroid.creditsValue; //update the credits amount in the HUD creditsVal.text = PlayerStats.instance.availableCredits.ToString(); //destroy the laser GameObject Destroy(collision.gameObject); //disable the collision of the asteroid GetComponent <Collider2D>().enabled = false; //set the asteroid to play its explosion animation GetComponent <Animator>().SetBool("IsDestroyed", true); //get a random amount of fragments to create based on the given min and max values int numFragments = Random.Range(parentAsteroid.minFragments, parentAsteroid.maxFragments + 1); for (int i = 0; i < numFragments; i++) { //generate a random size for the fragemnt float fragmentScale = Random.Range(0.4f, 0.6f); //select which fragment prefab to spawn int fragmentToAdd = Random.Range(0, parentAsteroid.fragments.Count - 1); //get the spawn location of the new fragment Vector3 fragmentPosition = parentAsteroid.fragmentSpawnLocation.transform.position; //instantiate a new fragment prefab GameObject newFragment = Instantiate(parentAsteroid.fragments[fragmentToAdd], fragmentPosition, parentAsteroid.transform.rotation); //adjust the scale of the new prefab newFragment.transform.localScale = new Vector3(fragmentScale, fragmentScale, fragmentScale); } //get the spawn positions within the game spawnPositions = GameObject.FindGameObjectsWithTag("Spawn Position"); //select a random spawn position int randPos = Random.Range(0, spawnPositions.Length); //create a vector with the new spawn postion Vector3 posInCam = spawnPositions[randPos].transform.position; //if the laser collided with an asteroid (NOT a fragment) if (CompareTag("Asteroid")) { //re-enable collision of the original asteroid GetComponent <Collider2D>().enabled = true; //instantiate a new asteroid in the random spawn location _ = Instantiate(asteroidPrefab, posInCam, Quaternion.identity); //disable the collision of the original asteroid again GetComponent <Collider2D>().enabled = false; } //if the asteroid collides with a player } else if (collision.CompareTag("Player")) { collision.enabled = false; //disable the player's collision collision.GetComponent <Animator>().SetBool("IsDead", true); //set the player to play its death animation collision.GetComponents <AudioSource>()[1].Stop(); //stop the thruster sound effect collision.GetComponents <AudioSource>()[2].Play(); //play the expolsion sound effect } }
private IEnumerator SpawnHazard() { int currentAstCount = AstSpawnCount; int currentEnemyCount = EnemySpawnCount; yield return(new WaitForSeconds(3)); while (true) { if (currentAstCount > 0 && currentEnemyCount > 0) { float randVal = Random.Range(0, 100f); if (randVal < 30) // enemy spawn { EnemyController enemy = enemyPool.GetFromPool(); enemy.transform.position = new Vector3(Random.Range(SpawnXMin, SpawnXMax), 0, SpawnZPos); yield return(new WaitForSeconds(.4f)); currentEnemyCount--; } else // asteroid spawn { AsteroidMovement ast = asteroidPool.GetFromPool(Random.Range(0, 3)); ast.transform.position = new Vector3(Random.Range(SpawnXMin, SpawnXMax), 0, SpawnZPos); yield return(new WaitForSeconds(.4f)); currentAstCount--; } } else if (currentAstCount > 0) { for (int i = 0; i < currentAstCount; i++) { AsteroidMovement ast = asteroidPool.GetFromPool(Random.Range(0, 3)); ast.transform.position = new Vector3(Random.Range(SpawnXMin, SpawnXMax), 0, SpawnZPos); yield return(new WaitForSeconds(.4f)); } currentAstCount = 0; } else if (currentEnemyCount > 0) { for (int i = 0; i < currentEnemyCount; i++) { EnemyController enemy = enemyPool.GetFromPool(); enemy.transform.position = new Vector3(Random.Range(SpawnXMin, SpawnXMax), 0, SpawnZPos); yield return(new WaitForSeconds(.4f)); } currentEnemyCount = 0; } else { currentAstCount = AstSpawnCount; currentEnemyCount = EnemySpawnCount; yield return(new WaitForSeconds(3)); } } }
private void Awake() { asteroidMovement = GetComponent <AsteroidMovement>(); spriteRenderer = GetComponent <SpriteRenderer>(); }