ludumdare50/Assets/Scripts/EnemySpawner.cs
2022-04-02 00:40:32 -04:00

28 lines
721 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemySpawner : MonoBehaviour {
public float delay;
public GameObject[] enemyPrefabs;
public Transform[] spawnPoints;
void Start() {
StartCoroutine(SpawnRoutine());
}
IEnumerator SpawnRoutine() {
while(true) {
yield return new WaitForSeconds(delay);
int enemyIndex = Random.Range(0, enemyPrefabs.Length);
int positionIndex = Random.Range(0, spawnPoints.Length);
GameObject newEnemy = Instantiate(enemyPrefabs[enemyIndex], spawnPoints[positionIndex].position, Quaternion.identity, transform);
}
}
}