You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
808 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
[SerializeField]
private GameObject enemyPrefab;
[SerializeField]
private GameObject enemyContainer;
private bool stopSpawning = false;
void Start()
{
StartCoroutine(SpawnRoutine());
}
IEnumerator SpawnRoutine()
{
while (!stopSpawning)
{
Vector3 posToSpawn = new Vector3(Random.Range(-8f, 8f), 7, 0);
GameObject newEnemy = Instantiate(enemyPrefab, posToSpawn, Quaternion.identity);
newEnemy.transform.SetParent(enemyContainer.transform);
yield return new WaitForSeconds(5.0f);
}
}
public void OnPlayerDeath()
{
stopSpawning = true;
}
}