```
chore(plastic): 更新 Plastic SCM 配置文件 更新了 .plastic/plastic.changes 和 .plastic/plastic.wktree 二进制配置文件以同步工作区状态。 ```
This commit is contained in:
1 parent
fac62a5560
commit
83263c1d21
12 files changed
+192
-461
No files matched your search
@@ -20,6 +20,10 @@ public class NewBehaviourScript : MonoBehaviour
|
||||
//攻击范围
|
||||
public float attackRange = 5f;
|
||||
|
||||
//基础攻击力,实际伤害结算逻辑后续接入
|
||||
[Min(0f)]
|
||||
public float attackPower = 10f;
|
||||
|
||||
//完整攻击动作时长,单位为秒;设置为0时使用动画真实时长
|
||||
[Min(0f)]
|
||||
public float attackDuration = 0f;
|
||||
@@ -45,6 +49,9 @@ public class NewBehaviourScript : MonoBehaviour
|
||||
//垂直速度
|
||||
private float verticalVelocity;
|
||||
|
||||
//当前攻击的伤害结算协程。
|
||||
private Coroutine attackDamageCoroutine;
|
||||
|
||||
//状态枚举
|
||||
public enum State
|
||||
{
|
||||
@@ -106,17 +113,10 @@ public class NewBehaviourScript : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
//没有目标时回到巡逻
|
||||
//场上没有敌人时进入待机,不再巡逻移动
|
||||
state = State.Alert;
|
||||
move(targetPos - transform.position);
|
||||
|
||||
//到达目标点时候随机目标点,只判断水平距离
|
||||
Vector3 patrolOffset = transform.position - targetPos;
|
||||
patrolOffset.y = 0;
|
||||
if (patrolOffset.sqrMagnitude < 0.01f)
|
||||
{
|
||||
randomTargetPos();
|
||||
}
|
||||
animator.SetInteger("speed", 0);
|
||||
applyGravity();
|
||||
}
|
||||
|
||||
//根据自身Tag找到敌对Tag
|
||||
@@ -248,15 +248,51 @@ public class NewBehaviourScript : MonoBehaviour
|
||||
|
||||
//根据目标攻击时长加速或减速完整攻击动画
|
||||
SetAttackAnimationSpeed();
|
||||
|
||||
animator.SetInteger("speed", 0);
|
||||
animator.SetTrigger("attack");
|
||||
state = State.Attack;
|
||||
|
||||
//在攻击动画中段结算伤害,而不是在动画开始瞬间扣血。
|
||||
if (attackDamageCoroutine != null)
|
||||
{
|
||||
StopCoroutine(attackDamageCoroutine);
|
||||
}
|
||||
|
||||
attackDamageCoroutine = StartCoroutine(ApplyAttackDamageInMiddle(friend));
|
||||
}
|
||||
|
||||
//等待半个完整攻击时长后,对目标扣除攻击力。
|
||||
private IEnumerator ApplyAttackDamageInMiddle(GameObject friend)
|
||||
{
|
||||
float fullAttackDuration = attackDuration > 0f
|
||||
? attackDuration
|
||||
: Mathf.Max(GetAttackAnimationDuration(), 0.01f);
|
||||
|
||||
yield return new WaitForSeconds(fullAttackDuration * 0.5f);
|
||||
|
||||
if (friend != null)
|
||||
{
|
||||
WorldHealthBar healthBar = friend.GetComponentInParent<WorldHealthBar>();
|
||||
if (healthBar != null)
|
||||
{
|
||||
healthBar.TakeDamage(attackPower);
|
||||
}
|
||||
}
|
||||
|
||||
attackDamageCoroutine = null;
|
||||
}
|
||||
|
||||
|
||||
// 在 Animator 的 Attack 动画结束时调用此方法
|
||||
public void OnAttackAnimationEnd()
|
||||
{
|
||||
if (attackDamageCoroutine != null)
|
||||
{
|
||||
StopCoroutine(attackDamageCoroutine);
|
||||
attackDamageCoroutine = null;
|
||||
}
|
||||
|
||||
//攻击动画结束后恢复Animator速度
|
||||
animator.speed = 1f;
|
||||
|
||||
@@ -268,9 +304,10 @@ public class NewBehaviourScript : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
//目标离开攻击范围,回到追踪或巡逻逻辑
|
||||
//目标离开攻击范围,回到待机逻辑
|
||||
state = State.Alert;
|
||||
randomTargetPos();
|
||||
animator.SetInteger("speed", 0);
|
||||
applyGravity();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user