Procházet zdrojové kódy

白鹭寻敌,跳字和落地调整

GrainFull před 3 měsíci
rodič
revize
9e16ef8bbd

+ 11 - 8
ActionTowerDefense/Assets/Resources/Prefab/Enemy/Enemy_1014.prefab

@@ -75,8 +75,8 @@ BoxCollider:
   m_IsTrigger: 1
   m_Enabled: 1
   serializedVersion: 2
-  m_Size: {x: 3.4691882, y: 6.0193615, z: 2}
-  m_Center: {x: 0.1, y: 0.35, z: 0}
+  m_Size: {x: 3.1726303, y: 6.0193615, z: 2}
+  m_Center: {x: 0.24827898, y: 0.3499999, z: 0}
 --- !u!114 &8924180071245218248
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -608,7 +608,7 @@ Transform:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 2616922587087395095}
   m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
-  m_LocalPosition: {x: 0, y: -0.96, z: 0}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
   m_Children: []
@@ -626,8 +626,8 @@ BoxCollider:
   m_IsTrigger: 0
   m_Enabled: 1
   serializedVersion: 2
-  m_Size: {x: 1.86, y: 2.8, z: 2}
-  m_Center: {x: 1.16, y: 2.96, z: 0}
+  m_Size: {x: 1.86, y: 3, z: 2}
+  m_Center: {x: 1.16, y: 1.5, z: 0}
 --- !u!1 &2623922659733331491
 GameObject:
   m_ObjectHideFlags: 0
@@ -1204,10 +1204,10 @@ MonoBehaviour:
   showInjuryNum: 1
   injuryNumText: {fileID: 6467251191553420251, guid: 9b37289f93ea76745ab2cefb79a93e3c, type: 3}
   injuryNumTextSummon: {fileID: 6467251191553420251, guid: 71b4c570c9e403d429846b71878a20c4, type: 3}
-  injuryNumPos_summon: {x: 1, y: 3}
+  injuryNumPos_summon: {x: 0, y: 1}
   injuryNumRandom_summon: {x: 1, y: 1}
-  injuryNumPos_march: {x: 1, y: 1}
-  injuryNumRandom_march: {x: 1, y: 3}
+  injuryNumPos_march: {x: 0, y: 1}
+  injuryNumRandom_march: {x: 1, y: 1}
   dieKeepTime: 0
   beHitDistance: 3
   attackDis: 0
@@ -1553,15 +1553,18 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   owner: {fileID: 1986582536140952583}
+  searchTrigger: {fileID: 3566347593191160092}
   targetRiseHeight: 10
   maxRiseHeight: 16
   upHeight: 3
+  findSpeed: 10
   dashSpeed: 70
   riseSpeed: 30
   breakDuration: 3.333
   dashDirection: {x: 0, y: -1, z: 0}
   riseDirection: {x: 0, y: 1, z: 0}
   canDash: 1
+  isFind: 1
   useLocalSpace: 1
   drag: 0
   maxSpeed: 2000

+ 57 - 2
ActionTowerDefense/Assets/Scripts/Skills/chargeDownward.cs

@@ -1,15 +1,19 @@
 using Sirenix.OdinInspector;
 using UnityEngine;
+using System;
 
 public class chargeDownward : MonoBehaviour
 {
     // 状态枚举
-    private enum MovementState { Idle, Dashing, Breaking, Rising }
+    public enum MovementState { Idle,Finding, Dashing, Breaking, Rising }
     private MovementState currentState = MovementState.Idle;
 
     public Enemy owner;
     private AttackController attackController;
     private Rigidbody rb;
+    public SearchTrigger searchTrigger;
+    BeSearchTrigger cloest = null;
+    private float cloestX = 0;
 
     [Header("移动参数")]
     [LabelText("目标上升高度")]
@@ -19,6 +23,7 @@ public class chargeDownward : MonoBehaviour
     public float upHeight = 4f;
 
     [LabelText("冲刺速度")]
+    public float findSpeed = 1f;
     public float dashSpeed = 1f; 
     public float riseSpeed = 1f;
 
@@ -31,6 +36,7 @@ public class chargeDownward : MonoBehaviour
 
     [LabelText("能否冲刺")]
     public bool canDash = true;
+    public bool isFind = true;
 
     [LabelText("是否使用本地坐标")]
     public bool useLocalSpace = true;
@@ -89,7 +95,11 @@ public class chargeDownward : MonoBehaviour
         switch (currentState)
         {
             case MovementState.Idle:
-                if (attackController.isAttackTriggerOn && canDash)
+                if (!attackController.isAttackTriggerOn && canDash && owner.state == CharacterState.Attack)
+                {
+                    Finding(searchTrigger.transform.position.x);
+                }
+                else if (attackController.isAttackTriggerOn && canDash)
                 {
                     StartDash();
                     currentState = MovementState.Dashing;
@@ -203,6 +213,8 @@ public class chargeDownward : MonoBehaviour
             owner.ChangeState(CharacterState.Idle);
             foot.GetComponent<Foot>().trigGroundList.Clear();
             foot.SetActive(true);
+            cloest = null;
+            isFind = true;
             return;
         }
 
@@ -224,6 +236,29 @@ public class chargeDownward : MonoBehaviour
         }
     }
 
+    public void Finding(float x)
+    {
+        if (cloest == null)
+        {
+            cloest = FindClosestTriggerByX(x);
+            if (cloest)
+            {
+                cloestX = cloest.transform.position.x;
+            }
+        }
+        else if (isFind && cloest)
+        {
+            float direction = Mathf.Sign(cloestX - x);
+            rb.velocity = Vector3.right * findSpeed * direction;
+            if (Mathf.Abs(cloestX - x)<0.1)
+            {
+                Debug.Log("寻找成功");
+                rb.velocity = Vector3.zero;
+                cloest = null;
+                isFind = false;
+            }
+        }
+    }
     public void StopAllMovements()
     {
         IsDashing = false;
@@ -247,4 +282,24 @@ public class chargeDownward : MonoBehaviour
     public bool IsRising { get; private set; }
     [ShowInInspector, ReadOnly]
     private bool isBreaking;
+
+    public BeSearchTrigger FindClosestTriggerByX(float selfX)
+    {
+        BeSearchTrigger closestTrigger = null;
+        float minDistance = float.MaxValue;
+
+        foreach (var keyValuePair in searchTrigger.trigCharacterDic)
+        {
+            foreach (var trigger in keyValuePair.Value)
+            {
+                float distance = Math.Abs(trigger.transform.position.x - selfX);
+                if (distance < minDistance)
+                {
+                    minDistance = distance;
+                    closestTrigger = trigger;
+                }
+            }
+        }
+        return closestTrigger;
+    }
 }