Enemy.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Enemy : MonoBehaviour
  5. {
  6. [SerializeField]
  7. private GameObject powerDrop;
  8. [SerializeField]
  9. private PowerLevels powerLevel;
  10. [SerializeField]
  11. private GameObject IndicatorCoverVeryLow;
  12. [SerializeField]
  13. private GameObject IndicatorCoverLow;
  14. [SerializeField]
  15. private GameObject IndicatorCoverMedium;
  16. [SerializeField]
  17. private GameObject IndicatorCoverHigh;
  18. [SerializeField]
  19. private GameObject IndicatorCoverFull;
  20. private float power = 1.0f;
  21. private enum PowerLevels { VeryLow, Low, Medium, High, Full }
  22. private EnemyAI.BehaviorController behaviorController;
  23. private DayTimeManager dayTimeManager;
  24. private bool dead = false;
  25. private DayTimeLabel lastCharging;
  26. void OnCollisionEnter(Collision collision)
  27. {
  28. if (!dead)
  29. {
  30. if (collision.collider.tag == "Bullet")
  31. {
  32. Death();
  33. }
  34. }
  35. }
  36. // Use this for initialization
  37. void Start()
  38. {
  39. dayTimeManager = GameObject.FindObjectOfType<DayTimeManager>();
  40. behaviorController = new EnemyAI.BehaviorController();
  41. behaviorController.blackboard.navMeshAgent = GetComponent<UnityEngine.AI.NavMeshAgent>();
  42. }
  43. // Update is called once per frame
  44. void Update()
  45. {
  46. if (!dead)
  47. {
  48. // AI
  49. EnemyAI.Blackboard blackboard = behaviorController.blackboard;
  50. if (dayTimeManager.dayTimeLabel == DayTimeLabel.Night)
  51. {
  52. blackboard.Night = true;
  53. }
  54. else
  55. {
  56. blackboard.Night = false;
  57. }
  58. blackboard.PlayerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
  59. blackboard.EnemyPosition = transform.position;
  60. behaviorController.Update();
  61. // Energy collection
  62. if (dayTimeManager.dayTimeLabel != lastCharging)
  63. {
  64. switch (dayTimeManager.dayTimeLabel)
  65. {
  66. case (DayTimeLabel.Night):
  67. powerLevel = PowerLevels.Full;
  68. power = 16;
  69. lastCharging = dayTimeManager.dayTimeLabel;
  70. IndicatorCoverVeryLow.SetActive(false);
  71. IndicatorCoverLow.SetActive(false);
  72. IndicatorCoverMedium.SetActive(false);
  73. IndicatorCoverHigh.SetActive(false);
  74. IndicatorCoverFull.SetActive(false);
  75. break;
  76. case (DayTimeLabel.Morning):
  77. powerLevel = PowerLevels.VeryLow;
  78. power = 1;
  79. lastCharging = dayTimeManager.dayTimeLabel;
  80. IndicatorCoverVeryLow.SetActive(false);
  81. IndicatorCoverLow.SetActive(true);
  82. IndicatorCoverMedium.SetActive(true);
  83. IndicatorCoverHigh.SetActive(true);
  84. IndicatorCoverFull.SetActive(true);
  85. break;
  86. case (DayTimeLabel.Noon):
  87. powerLevel = PowerLevels.Low;
  88. power = 2;
  89. lastCharging = dayTimeManager.dayTimeLabel;
  90. IndicatorCoverVeryLow.SetActive(false);
  91. IndicatorCoverLow.SetActive(false);
  92. IndicatorCoverMedium.SetActive(true);
  93. IndicatorCoverHigh.SetActive(true);
  94. IndicatorCoverFull.SetActive(true);
  95. break;
  96. case (DayTimeLabel.Evening):
  97. powerLevel = PowerLevels.Medium;
  98. power = 4;
  99. lastCharging = dayTimeManager.dayTimeLabel;
  100. IndicatorCoverVeryLow.SetActive(false);
  101. IndicatorCoverLow.SetActive(false);
  102. IndicatorCoverMedium.SetActive(false);
  103. IndicatorCoverHigh.SetActive(true);
  104. IndicatorCoverFull.SetActive(true);
  105. break;
  106. }
  107. }
  108. }
  109. }
  110. private void Death()
  111. {
  112. dead = true;
  113. GetComponent<UnityEngine.AI.NavMeshAgent>().isStopped = true;
  114. GameObject go = GameObject.Instantiate(powerDrop);
  115. go.GetComponent<PowerDrop>().powerAmount = power;
  116. go.transform.position = gameObject.transform.position;
  117. GameObject.Destroy(gameObject);
  118. }
  119. }