/// <summary> /// 有限状态机状态进入时调用。 /// </summary> /// <param name="fsm">有限状态机引用。</param> protected override void OnEnter(IFsm <Monster> fsm) { base.OnEnter(fsm); hurtTimeCounter = 0; // 积累受伤次数 if (preHurtTime != 0 && Time.time - preHurtTime < 2.5f) { hurtTimes++; } else { preHurtTime = 0; hurtTimes = 0; } // 累积受伤3次,则向后弹一段距离 if (hurtTimes == 3) { Vector3 pos = PositionUtility.GetAjustPositionWithMap(fsm.Owner.CachedTransform.position - fsm.Owner.CachedTransform.forward * 2); fsm.Owner.CachedTransform.DOMove(pos, 0.5f); hurtTimes = 0; } // 播放动画 fsm.Owner.ChangeAnimation(FightEntityAnimationState.hurt); // 执行受伤逻辑 int damageHP = fsm.GetData <VarInt> (Constant.EntityData.DamageHP).Value; fsm.Owner.OnDamage(damageHP); preHurtTime = Time.time; }
/// <summary> /// 向前移动 /// </summary> /// <param name="distance"></param> public void Forward(float distance) { Vector3 nextPos = CachedTransform.position + CachedTransform.forward * distance * fightEntityData.MoveSpeed; CachedTransform.position = PositionUtility.GetAjustPositionWithMap(nextPos); }