Преглед изворни кода

agent寻路停止,错误捕捉

lvjincheng пре 4 година
родитељ
комит
7f52779909
1 измењених фајлова са 7 додато и 3 уклоњено
  1. 7 3
      Assets/BowArrow/Scenes/GameChallengeScene/Wolf.cs

+ 7 - 3
Assets/BowArrow/Scenes/GameChallengeScene/Wolf.cs

@@ -127,12 +127,16 @@ public class Wolf : TargetAnimal
         }
         AudioMgr.ins.PlayAnimalEffect("wolf_injured", AudioMgr.GetAudioSource(this.gameObject));
     }
+
+    void SetAgentStopped(bool value) { //要捕捉错误,不然会报错
+        try { this.agent.isStopped = value; } catch (System.Exception) {}
+    }
     
     //启动寻路
     void SetDestination(Vector3 pos) {
         state.ResetActionState();
         state.moving = true;
-        this.agent.isStopped = false;
+        SetAgentStopped(false);
         if (useRunbackPoint) {
             useRunbackPoint = false;
             WolfActGrid.ins.areaMatrix.releaseOccupy(this);
@@ -147,7 +151,7 @@ public class Wolf : TargetAnimal
     //寻路结束
     void OnReachDestination() {
         if (!state.moving) return;
-        this.agent.isStopped = true;
+        SetAgentStopped(true);
         state.ResetActionState();
     }
     //是否已经接近目的地(寻路完成判断)
@@ -455,7 +459,7 @@ public class Wolf : TargetAnimal
     void Stay(bool correct = false) {
         if (state.moving || correct) {
             this.agent.destination = this.agent.nextPosition;
-            this.agent.isStopped = true;
+            SetAgentStopped(true);
         }
         state.ResetActionState();
         state.staying = true;