123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
-
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- public class EnemyMovement : MonoBehaviour {
- NavMeshAgent agent;
- Transform Exit;
- public int baseMaxHealth = 100;
- public int speed = 10;
- public int scoreValue = 10;
- public int killManaReward = 5;
- public int level = 0;
- public int currentHealth;
- float slowTime = 0f;
- Vector3 startPos;
- public int CurrentHealth
- {
- get { return currentHealth; }
- }
- public int MaxHealth
- {
- get { return baseMaxHealth + 10 * level; }
- }
- public float CurrentHealthPercent
- {
- get { return (float)currentHealth / (float)MaxHealth; }
- }
- public int EffectiveSpeed
- {
- get
- {
- int output = speed;
- if (slowTime > 0) output /= 5;
- return output;
- }
- }
- void Start () {
-
- agent = GetComponent<NavMeshAgent>();
-
- agent.destination = Nexus.CurrentInstance.transform.position;
-
- currentHealth = MaxHealth;
-
- killManaReward = killManaReward + level * 5;
-
- startPos = transform.position;
- }
-
-
- void FixedUpdate () {
-
- if (slowTime > 0)
- {
- slowTime -= Time.deltaTime;
-
- }
- agent.speed = EffectiveSpeed;
- }
-
-
-
- public float RemainingDistance
- {
- get
- {
- float distance = 0.0f;
- if (agent == null) return float.MaxValue;
- Vector3[] corners = agent.path.corners;
- for (int c = 0; c < corners.Length - 1; ++c)
- {
-
- distance += Mathf.Abs((corners[c] - corners[c + 1]).magnitude);
- }
-
- return distance;
- }
- }
-
-
-
-
- public void Damage(int amount)
- {
-
- currentHealth -= amount;
-
- if (currentHealth <= 0)
- {
- Destroy(gameObject);
-
- Nexus.CurrentInstance.GainMana(killManaReward);
-
- }
- }
-
-
-
-
- public void SlowDown(float time)
- {
- if (slowTime < time) slowTime = time;
-
- }
-
- void OnTriggerEnter(Collider col)
- {
-
- if (col.CompareTag("Exit"))
- {
-
- col.GetComponent<Nexus>().Damage(CurrentHealth);
-
- agent.Warp(startPos);
-
- agent.destination = Nexus.CurrentInstance.transform.position;
- }
- }
- }
|