using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using StarterAssets;
public class EnemySpawner : MonoBehaviour
{
[SerializeField] public EnemyAi enemyPrefab;
[SerializeField] private Transform player;
[SerializeField] private float enemyInterval = 3.5f;
// Start is called before the first frame update
void Start()
{
StartCoroutine(spawnEnemy(enemyInterval, enemyPrefab));
}
// Update is called once per frame
void Update()
{
}
private IEnumerator spawnEnemy(float interval, EnemyAi enemy)
{
yield return new WaitForSeconds(interval);
if (GameObject.FindGameObjectsWithTag("Enemy").Length < 10)
{
EnemyAi newEnemy = Instantiate(enemy, new Vector3(Random.Range(-5f, 5), Random.Range(-6f, 6f), 1), Quaternion.identity);
newEnemy.target = player;
}
StartCoroutine(spawnEnemy(interval, enemy));
}
}