Spawner.cs 580 B

12345678910111213141516171819202122232425262728
  1. using System.Collections;
  2. using UnityEngine;
  3. public class Spawner : MonoBehaviour
  4. {
  5. public GameObject enemyPrefab;
  6. public GameManager gameManager;
  7. void Start()
  8. {
  9. StartCoroutine(SpawnLoop());
  10. }
  11. void Update()
  12. {
  13. }
  14. IEnumerator SpawnLoop() //Spawn random Enemy around Player every 3s
  15. {
  16. while (gameManager.gameRunning)
  17. {
  18. Vector3 randomSpot = Random.onUnitSphere * 3f;
  19. Instantiate(enemyPrefab, randomSpot, Quaternion.identity);
  20. yield return new WaitForSeconds(3f);
  21. }
  22. }
  23. }