IEnumerator SpawnEnemyLookAt() { int n = numberOfLookAtEnemies; yield return(new WaitForSeconds(1.0f)); while (true) { for (int i = 0; i < n; i++) { Vector3 spawnPosition = new Vector3(Random.Range(look_Boundary.xMin, look_Boundary.xMax), transform.position.y, transform.position.z); Quaternion spawnRotation = Quaternion.identity; enemy_Clone = Instantiate(enemys[1].enemy_Prefab, spawnPosition, spawnRotation) as GameObject; AimAtPlayer aim = enemy_Clone.AddComponent <AimAtPlayer>(); //Rigidbody clone_Rigidbody = enemy_Clone.GetComponent<Rigidbody>(); //clone_Rigidbody.velocity = -transform.forward * enemy.speed; yield return(new WaitForSeconds(Random.Range(.5f, 2f))); } n += Random.Range(-1, 4); if (n < 2) { n = 2; } Debug.Log("Look enemies to spawn per wave: " + n); yield return(new WaitForSeconds(Random.Range(3, 5))); } }
public override void Start() { base.Start(); navMeshAgent = GetComponent <NavMeshAgent>(); playerStats = GameObject.Find("player").GetComponent <PlayerStats>(); playerTransform = GameObject.Find("player").transform; mainCamera = GameObject.Find("mainCamera").transform; enemyStats = GetComponent <EnemyStats>(); aimAtPlayer = GetComponentInChildren <AimAtPlayer>(); aimAtPlayer.enabled = false; if (projectileReleaseTransform == null) { projectileReleaseTransform = transform; } }