EnemySpawner.cs 926 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class EnemySpawner : MonoBehaviour
  5. {
  6. [SerializeField]
  7. private GameObject EnemyPrefab;
  8. [SerializeField]
  9. private float cooldownForSpawning = 2.0f;
  10. private float timer;
  11. private DayTimeManager dayTimeManager;
  12. // Use this for initialization
  13. void Start ()
  14. {
  15. dayTimeManager = FindObjectOfType<DayTimeManager>();
  16. }
  17. // Update is called once per frame
  18. void Update ()
  19. {
  20. if (dayTimeManager.dayTimeLabel == DayTimeLabel.Night)
  21. {
  22. timer += Time.deltaTime;
  23. if (timer > cooldownForSpawning)
  24. {
  25. SpawnEnemy();
  26. timer = 0.0f;
  27. }
  28. }
  29. }
  30. private void SpawnEnemy()
  31. {
  32. GameObject enemy = GameObject.Instantiate(EnemyPrefab);
  33. enemy.transform.position = this.transform.position;
  34. }
  35. }