lvjincheng 4 роки тому
батько
коміт
13bc13cc31

+ 54 - 4
Assets/BowArrow/Scenes/GameChallengeScene/Wolf.cs

@@ -2,6 +2,7 @@ using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.AI;
+using DG.Tweening;
 
 public class Wolf : TargetAnimal
 {
@@ -175,24 +176,70 @@ public class Wolf : TargetAnimal
         this.willMoveTime = Random.value * 3 + 5;
     }
 
+
+    //起跳点
+    Vector3 jumpPoint;
+    //落地点
+    Vector3 landPoint;
     //攻击
     void Attack() {
         state.ResetActionState();
         state.attacking = true;
         curAnimIndex = -1; /*注意:这样可避免狼两次使用同一攻击动作而第二次无法播放的情况 */
         int hurtValue = 2;
-        if (Random.value < 0.5) {
+        if (canAttackID == "A") {
             state.attackA = true;
-        } else {
+            #region //起点和终点计算
+                jumpPoint = this.transform.position;
+                Vector3 hunterPos = hunterPosition;
+                hunterPos.y = jumpPoint.y;
+                Vector3 deltaPointer = jumpPoint - hunterPos;
+                landPoint = hunterPos + deltaPointer.normalized * 2f;
+            #endregion
+            Vector3 displace = landPoint - jumpPoint;
+            float baseoffset = this.agent.baseOffset;
+            Sequence seq = DOTween.Sequence();
+            seq.Append(DOTween.To(() => 0f, value => {
+                this.transform.position = jumpPoint + displace * value;
+                if (value < 0.5) {
+                    this.agent.baseOffset = baseoffset + value;
+                } else {
+                    this.agent.baseOffset = baseoffset + (1 - value);
+                }
+            }, 1f, 0.6f));
+            seq.AppendCallback(delegate() {
+                this.transform.position = landPoint;
+                if (!state.dead) onAttack?.Invoke(this, hurtValue);
+            });
+            seq.Append(DOTween.To(() => 0f, value => {
+                this.transform.position = landPoint;
+            }, 1f, 0.634f));
+            seq.AppendCallback(delegate() {
+                if (!state.dead) stopAniAttackA();
+                this.transform.position = landPoint;
+            });
+            seq.Append(DOTween.To(() => 0f, value => {
+                this.transform.position = landPoint;
+            }, 1f, 0.1f)); //通过dotween是它不被动画的位移影响;
+        } else if (canAttackID == "B") {
             state.attackB = true;
             hurtValue = 3;
+            onAttack?.Invoke(this, hurtValue);
         }
-        onAttack?.Invoke(this, hurtValue);
     }
     //跑到能攻击玩家的坐标点
+    string canAttackID = null;
     void RunToAttackHunter() {
+        float needDistance;
+        if (Random.value < 0.33f) {
+            needDistance = 2;
+            canAttackID = "B";
+        } else {
+            needDistance = 8;
+            canAttackID = "A";
+        }
         Vector3 standardPointer = animalsBaseT.forward;
-        Vector3 newPos = animalsBaseT.position + standardPointer * 1.5f;
+        Vector3 newPos = animalsBaseT.position + standardPointer * needDistance;
         SetDestination(newPos);
         state.moveQuickly = true;
         agent.speed = 5f;
@@ -292,6 +339,9 @@ public class Wolf : TargetAnimal
     bool isAniAttakA() {
         return curAnimIndex == 1;
     }
+    void stopAniAttackA() {
+        ap.StopAnimation(1);
+    }
     void playAniAttakB() {
         ap.play(curAnimIndex = 0, WrapMode.Once);
     }

+ 1 - 1
Assets/BowArrow/Scenes/GameChallengeScene/WolfHuntGameMode.cs

@@ -104,7 +104,6 @@ public class WolfHuntGameMode : ChallengeGameMode
     public int hpMax = 20;
     public void OnAttacked(Wolf wolf, int hurtValue) {
         if (hp <= 0) return;
-        AudioMgr.ins.PlayAnimalEffect("man_injured", AudioMgr.GetAudioSource(this.gameMgr.gameObject));
 
         //看下是否满足受伤距离
         Vector3 p1 = wolf.transform.position;
@@ -114,6 +113,7 @@ public class WolfHuntGameMode : ChallengeGameMode
         if (distance > 3) return;
 
         hp -= hurtValue;
+        AudioMgr.ins.PlayAnimalEffect("man_injured", AudioMgr.GetAudioSource(this.gameMgr.gameObject));
         DoTweenHurt();
         if (hp <= 0) {
             hp = 0;

+ 5 - 0
Assets/BowArrow/Scripts/Components/AnimationPlayer.cs

@@ -98,6 +98,11 @@ public class AnimationPlayer : MonoBehaviour
             }
         }
     }
+
+    public void StopAnimation(int index) {
+        string name = this.animationClips[index].name;
+        animationMain.Stop(name);
+    }
 }
 
 public class AnimationPlayerCompleteResult {