EnemyController.cs 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using UnityEngine;
  2. public class EnemyController : MonoBehaviour
  3. {
  4. GameManager gameManager;
  5. public float duration = 5;
  6. private float timeRemaining = 5;
  7. public int pointReward = 0;
  8. // Start is called once before the first execution of Update after the MonoBehaviour is created
  9. void Start()
  10. {
  11. if (gameManager == null)
  12. {
  13. gameManager = FindFirstObjectByType<GameManager>();
  14. }
  15. }
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. timeRemaining -= Time.deltaTime;
  20. if (timeRemaining <= 0)
  21. {
  22. Destroy(gameObject);
  23. gameManager.NotifyEnemyDeath(0);
  24. }
  25. }
  26. public void SetValues(float duration, int pointReward)
  27. {
  28. this.duration = duration;
  29. timeRemaining = this.duration;
  30. this.pointReward = pointReward;
  31. }
  32. private void OnTriggerEnter(Collider other)
  33. {
  34. if (other.CompareTag("Projectile"))
  35. {
  36. Destroy(gameObject);
  37. Destroy(other.gameObject);
  38. gameManager.NotifyEnemyDeath(pointReward);
  39. }
  40. }
  41. }