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.

35 lines
808 B

1 year ago
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);
1 year ago
newEnemy.transform.SetParent(enemyContainer.transform);
1 year ago
yield return new WaitForSeconds(5.0f);
}
}
public void OnPlayerDeath()
{
stopSpawning = true;
}
}