using System.Collections; using System.Collections.Generic; using UnityEngine; // 枚举:五行类型 public enum ElementType { Metal, Wood, Water, Fire, Earth } // 枚举:防御类型 public enum DefenseType { HeavyArmor,//重甲 LightArmor,//轻甲 MagicShield,//魔盾 SpiritForm//灵体 } // 枚举:单位类型 public enum UnitType { GroundUnit,//地面单位 AirUnit//空中单位 } // 枚举:体型类型 public enum Size { Small,//小 Large//大 } public class enemy : Role { public string enemyId; [Header("移动速度")] public float moveSpeed; [Header("萌妖头像")] public Sprite MengyaoSprite; [Header("萌妖技能图标")] public List SkillSprites; [HideInInspector] public float harmNumber = 0; // 伤害 public float HarmNumber { get => harmNumber; set { harmNumber = value; //Debug.Log(enemyId + "总伤害" + harmNumber); } } private float originalMoveSpeed; // 记录初始的移动速度 private float slowDownTime = 0f; // 记录减速开始时间 private bool isSlowed = false; // 标记是否处于减速状态 [Header("防御力")] public float Defense; // 扣减玩家生命值(假设每次攻击的伤害) [Header("扣减玩家生命值")] public float DamageToPlayer; // 每级提升生命值 [Header("每级提升生命值")] public float HealthPerLevel; // 每级提升防御力 [Header("每级提升防御力")] public float DefensePerLevel; [Header("五行类型")] public ElementType elementType; [Header("防御类型")] public DefenseType defenseType; public override void Start() { base.Start(); originalMoveSpeed = moveSpeed; // 保存初始移动速度 if (camp == Camp.Enemy) { if (AnimationTree != null) { AnimationTree[0].CharacterAnimationFrameInterval = (int)(36 / moveSpeed); } //开始移动 Init(InitEnenyData.instance.GetRandomWaypoints()); } } public void Init(waypoints _waypoints) { base.Navigation.waypoints = _waypoints; //开始移动 Navigation.MoveToNextWaypoint(this.gameObject, moveSpeed); } private void OnTriggerEnter2D(Collider2D collision) { // 进入范围检测 if (this.camp == Camp.Enemy && collision.tag == "House") { UIContorl.instance.Hp -= 1; UIContorl.instance.ShowRedMask(); Destroy(this.gameObject); } } // 减速并在指定时间后恢复原速度 public override void SlowDown(float slowFactor, float duration) { if (!isSlowed) { //Debug.Log("减速------------------------"); // 临时设置减速后的速度 moveSpeed *= slowFactor; // 如果有动画控制,更新动画速度 if (AnimationTree != null) { AnimationTree[0].CharacterAnimationFrameInterval = (int)(36 / moveSpeed); } Navigation.ChangeSpeed(slowFactor, duration); // 标记减速状态 isSlowed = true; // 记录减速开始时间 slowDownTime = Time.time; } } void Update() { if (isSlowed) { // 检查减速时间是否到了 if (Time.time - slowDownTime >= 3f) // 3秒后恢复原速度 { // 恢复初始速度 moveSpeed = originalMoveSpeed; // 恢复动画速度 if (AnimationTree != null) { foreach (var anim in AnimationTree) { anim.CharacterAnimationFrameInterval = (int)(36 / moveSpeed); } } // 取消减速状态 isSlowed = false; } } } }