| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Enemy : MonoBehaviour
- {
- [SerializeField]
- private GameObject powerDrop;
- [SerializeField]
- private PowerLevels powerLevel;
- [SerializeField]
- private GameObject IndicatorCoverVeryLow;
- [SerializeField]
- private GameObject IndicatorCoverLow;
- [SerializeField]
- private GameObject IndicatorCoverMedium;
- [SerializeField]
- private GameObject IndicatorCoverHigh;
- [SerializeField]
- private GameObject IndicatorCoverFull;
- private float power = 1.0f;
- private enum PowerLevels { VeryLow, Low, Medium, High, Full }
- private EnemyAI.BehaviorController behaviorController;
- private DayTimeManager dayTimeManager;
- private float health;
- private DayTimeLabel lastCharging;
- public float maxHealth = 2.5f;
- private bool dead;
- public AudioClip explosion;
- public AudioClip[] hitMe;
- public WeaponEnemy weapon;
- void OnCollisionEnter(Collision collision)
- {
- if (!dead)
- {
- if (collision.collider.tag == "Bullet")
- {
- Player.AudioSource.clip = hitMe[Random.Range(0, 1) > 0.5 ? 0 : 1];
- Player.AudioSource.Play();
- health -= 1f;
- }
- }
- if (health <= 0)
- Death();
- }
- // Use this for initialization
- void Start()
- {
- health = maxHealth;
- dayTimeManager = GameObject.FindObjectOfType<DayTimeManager>();
- behaviorController = new EnemyAI.BehaviorController();
- behaviorController.blackboard.Weapon = weapon;
- behaviorController.blackboard.navMeshAgent = GetComponent<UnityEngine.AI.NavMeshAgent>();
- }
- // Update is called once per frame
- void Update()
- {
- if (!dead)
- {
- // AI
- EnemyAI.Blackboard blackboard = behaviorController.blackboard;
- if (dayTimeManager.dayTimeLabel == DayTimeLabel.Night)
- {
- blackboard.Night = true;
- }
- else
- {
- blackboard.Night = false;
- }
- blackboard.PlayerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
- blackboard.EnemyPosition = transform.position;
- behaviorController.Update();
- // Energy collection
- if (dayTimeManager.dayTimeLabel != lastCharging)
- {
- switch (dayTimeManager.dayTimeLabel)
- {
- case (DayTimeLabel.Night):
- powerLevel = PowerLevels.Full;
- power = 16;
- lastCharging = dayTimeManager.dayTimeLabel;
- IndicatorCoverVeryLow.SetActive(false);
- IndicatorCoverLow.SetActive(false);
- IndicatorCoverMedium.SetActive(false);
- IndicatorCoverHigh.SetActive(false);
- IndicatorCoverFull.SetActive(false);
- break;
- case (DayTimeLabel.Morning):
- powerLevel = PowerLevels.VeryLow;
- power = 1;
- lastCharging = dayTimeManager.dayTimeLabel;
- IndicatorCoverVeryLow.SetActive(false);
- IndicatorCoverLow.SetActive(true);
- IndicatorCoverMedium.SetActive(true);
- IndicatorCoverHigh.SetActive(true);
- IndicatorCoverFull.SetActive(true);
- break;
- case (DayTimeLabel.Noon):
- powerLevel = PowerLevels.Low;
- power = 2;
- lastCharging = dayTimeManager.dayTimeLabel;
- IndicatorCoverVeryLow.SetActive(false);
- IndicatorCoverLow.SetActive(false);
- IndicatorCoverMedium.SetActive(true);
- IndicatorCoverHigh.SetActive(true);
- IndicatorCoverFull.SetActive(true);
- break;
- case (DayTimeLabel.Evening):
- powerLevel = PowerLevels.Medium;
- power = 4;
- lastCharging = dayTimeManager.dayTimeLabel;
- IndicatorCoverVeryLow.SetActive(false);
- IndicatorCoverLow.SetActive(false);
- IndicatorCoverMedium.SetActive(false);
- IndicatorCoverHigh.SetActive(true);
- IndicatorCoverFull.SetActive(true);
- break;
- }
- }
- }
- }
- private void Death()
- {
- Player.AudioSource.clip = explosion;
- Player.AudioSource.pitch = 1.0f;
- Player.AudioSource.Play();
- dead = true;
- GetComponentInChildren<WeaponEnemy>().enabled = false;
- GetComponent<UnityEngine.AI.NavMeshAgent>().isStopped = true;
- GameObject go = GameObject.Instantiate(powerDrop);
- go.GetComponent<PowerDrop>().powerAmount = power;
- go.transform.position = gameObject.transform.position;
- GameObject.Destroy(gameObject);
- }
- }
|