Просмотр исходного кода

野鸡和狼加入阻碍优先级,狼起跳位置随机

lvjincheng 4 лет назад
Родитель
Сommit
bdb3ee098f

+ 20 - 8
Assets/BowArrow/Scenes/GameChallengeScene/Wolf.cs

@@ -21,8 +21,19 @@ public class Wolf : TargetAnimal
     {
         initAniListener();
         InitAutoStrategy();
+        this.agent.avoidancePriority = avoidancePriority;
+    }
+    static int _avoidancePriority = 0;
+    static int avoidancePriority {
+        get {
+            if (_avoidancePriority < 50) {
+                _avoidancePriority++;
+            } else {
+                _avoidancePriority = 1;
+            }
+            return _avoidancePriority;
+        }
     }
-
 
     void Update()
     {
@@ -231,15 +242,16 @@ public class Wolf : TargetAnimal
     string canAttackID = null;
     void RunToAttackHunter() {
         float needDistance;
-        if (Random.value < 0.33f) {
-            needDistance = 2;
-            canAttackID = "B";
-        } else {
+        Vector3 displace = animalsBaseT.forward;
+        // if (Random.value < 0.33f) {
+        //     needDistance = 2;
+        //     canAttackID = "B";
+        // } else {
+            displace = Quaternion.AngleAxis(Random.Range(-30f, 30f), Vector3.up) * displace;
             needDistance = 8;
             canAttackID = "A";
-        }
-        Vector3 standardPointer = animalsBaseT.forward;
-        Vector3 newPos = animalsBaseT.position + standardPointer * needDistance;
+        // }
+        Vector3 newPos = animalsBaseT.position + displace * needDistance;
         SetDestination(newPos);
         state.moveQuickly = true;
         agent.speed = 5f;

+ 12 - 0
Assets/BowArrow/Scenes/GameChallengeScene/Yeji.cs

@@ -24,6 +24,18 @@ public class Yeji : TargetAnimal
     {
         ap = GetComponent<AnimationPlayer>();
         agent = GetComponent<NavMeshAgent>();
+        this.agent.avoidancePriority = avoidancePriority;
+    }
+    static int _avoidancePriority = 0;
+    static int avoidancePriority {
+        get {
+            if (_avoidancePriority < 50) {
+                _avoidancePriority++;
+            } else {
+                _avoidancePriority = 1;
+            }
+            return _avoidancePriority;
+        }
     }
 
     void Start()