Răsfoiți Sursa

新增平台条件:可以优先行走

WGL 4 luni în urmă
părinte
comite
ae346fce7a

+ 13 - 9
ActionTowerDefense/Assets/Scripts/Characters/Foot.cs

@@ -44,19 +44,23 @@ public class Foot : MonoBehaviour
             platform = null;
             foreach (var item in trigGroundList)
             {
-                platform = item.GetComponent<Platform>();
-                if (platform!=null)
+                Platform newPlatform = item.GetComponent<Platform>();
+                if (newPlatform != null)
                 {
-                    if (moveCharacter.transform.position.x < platform.right.position.x 
-                        && moveCharacter.transform.position.x > platform.left.position.x)
+                    if (moveCharacter.transform.position.x < newPlatform.right.position.x 
+                        && moveCharacter.transform.position.x > newPlatform.left.position.x)
                     {
-                        break;
+                        if(platform == null)
+                        {
+                            platform = newPlatform;
+                        }
+                        else if (newPlatform.haveMagnetic)
+                        {
+                            platform = newPlatform;
+                        }
+                        
                     }
                 }
-                else
-                {
-                    break;
-                }
             }
             
 

+ 10 - 7
ActionTowerDefense/Assets/Scripts/Platform.cs

@@ -1,13 +1,18 @@
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using Sirenix.OdinInspector;
 
 public class Platform : MonoBehaviour
 {
-    public Rigidbody rb;
-    public List<Foot> feet = new List<Foot>();
-    public Transform left;
-    public Transform right;
+    [FoldoutGroup("组件")] public Rigidbody rb;
+    [FoldoutGroup("组件")] public List<Foot> feet = new List<Foot>();
+    [FoldoutGroup("组件")] public Transform left;
+    [FoldoutGroup("组件")] public Transform right;
+
+    [FoldoutGroup("条件")] [LabelText("是否可以下平台")] public bool canDown = true;
+    [FoldoutGroup("条件")] [LabelText("是否优先行走")] public bool haveMagnetic;
+
     public bool TrigFeet
     {
         get
@@ -15,9 +20,7 @@ public class Platform : MonoBehaviour
             return feet.Count > 0;
         }
     }
-    //public float edgeDistance;
-
-    public bool canDown = true;
+    
 
     private void OnTriggerEnter(Collider other)
     {