//Causes a separate thread to run that moves the enemy IEnumerator Move() { //Loops through all the enemy movement patterns for (int i = 0; i < enemyMovements.Length; i += 1) { //Sets currentMovement for the Shoot thread currentMovement = enemyMovements[i]; //o represents how long the enemy should be moving in this given direction for float o = enemyMovements[i].z; //While enemy should still be moving while (o > 0) { //Move enemy transform.position += new Vector3(enemyMovements[i].x, 0, enemyMovements[i].y) * movementSpeed * Time.deltaTime; //If enemy is beyond left/right boundaries, move it back inside if (transform.position.x < bottomLeft.x + 1 || transform.position.x > topRight.x - 1) { transform.position -= new Vector3(enemyMovements[i].x, 0, 0) * movementSpeed * Time.deltaTime; } //If enemy is further than the bottom of players screen, KILL IT if (transform.position.z < bottomLeft.z - 1) { if (GameManager.current.CurrentState != GameManager.State.NumberOfEnemies) { Destroy(gameObject); } else { } } o -= Time.deltaTime; //If enemy is dead, cause explosion, and destroy the enemy if (health <= 0) { //GO THROUGH DROPPABLES TO DROP ITEMS??? for (int g = 0; g < droppables.Length; g += 1) { int value = Random.Range(0, 100); if (value < 50) { Collect collect = Instantiate(droppables[g].gameObject, transform.position + new Vector3(Random.Range(-1, 1), 0, Random.Range(-1, 1)), Quaternion.identity).GetComponent <Collect>(); collect.SetState(movementSpeed); } } CameraShake.current.Shake(destructionValue, destructionTimeValue); GetComponent <Hazard>().playerDestroyed = true; GameManager.current.SpawnExplosion(transform.position); Destroy(gameObject); } yield return(new WaitForEndOfFrame()); } //Reset the movement loop if (i == enemyMovements.Length - 1) { i = -1; } } yield return(null); }