using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
[Header("Enemy Prefabs")]
public GameObject[] enemiesToSpawn;
[Header("Spawns")]
public float spawnDelay;
public bool spawned = false;
[Header("Components")]
public Transform tf;
public GameObject enemyCounter;
public EnemyCounter eCounter;
private void Awake()
{
tf = GetComponent();
enemyCounter = GameObject.FindGameObjectWithTag("EnemyCounter");
eCounter = enemyCounter.GetComponent();
}
private void Update()
{
StartCoroutine(SpawnDelay());
}
IEnumerator SpawnDelay()
{
if (!spawned)
{
eCounter.enemiesSpawned++;
Instantiate(enemiesToSpawn[Random.Range(0, enemiesToSpawn.Length)], transform.position, transform.rotation);
spawned = true;
yield return new WaitForSeconds(spawnDelay);
spawned = false;
}
}
}
↧