Selaa lähdekoodia

boss可向塔移动

SZAND\msx_2 1 vuosi sitten
vanhempi
commit
129d5083e8

+ 7 - 1
ActionTowerDefense/Assets/Resources/Prefab/Boss/Boss_YuMenGuan.prefab

@@ -976,7 +976,7 @@ MonoBehaviour:
   extraRiseGravity: 0
   extraFallGravity: -10
   canMove: 1
-  moveSpeed: 5
+  moveSpeed: 1
   totalBeRepelValue: 0
   beRepelValue: 0
   weakTime: 0
@@ -1045,6 +1045,12 @@ MonoBehaviour:
   curStateId: 0
   restWeaknessNum: 0
   coreDamageRate: 2
+  curTarget: 2
+  attackConfigurations:
+  - category: 0
+    attacks: 000000000100000002000000
+  - category: 0
+    attacks: 0300000004000000
 --- !u!1 &6139679835290116115
 GameObject:
   m_ObjectHideFlags: 0

+ 37 - 2
ActionTowerDefense/Assets/Scripts/Boss/Boss.cs

@@ -133,6 +133,18 @@ public class Boss : MoveCharacter
         }
     }
 
+    public override void FixedUpdate()
+    {
+        if (canMove)
+        {
+            OnMove();
+        }
+        else
+        {
+            rb.velocity = new Vector3(0, 0, 0);
+        }
+    }
+
     public override void ChangeState(CharacterState newState)
     {
         switch (newState)
@@ -147,7 +159,6 @@ public class Boss : MoveCharacter
 
     public virtual void OnMove()
     {
-        
     }
 
     public void CheckTarget()
@@ -168,10 +179,34 @@ public class Boss : MoveCharacter
                 }
                 break;
             case TargetType.Player:
-
+                PlayerController p1 = PlayersInput.instance[0];
+                PlayerController p2 = PlayersInput.instance[1];
+                bool p1Alive = (p1 != null && !p1.isRevive);
+                bool p2Alive = (p2 != null && !p2.isRevive);
+                float dis1 = Vector2.Distance(transform.position, p1.transform.position);
+                float dis2 = Vector2.Distance(transform.position, p2.transform.position);
+                if (p1Alive)
+                {
+                    if (p2Alive)
+                    {
+                        curTar = dis1 > dis2 ? p1 : p2;
+                    }
+                    else
+                    {
+                        curTar = p1;
+                    }
+                }
+                else
+                {
+                    if(p2Alive)
+                    {
+                        curTar = p2;
+                    }
+                }
                 break;
             default:
                 break;
         }
+        targetCharacter = curTar;
     }
 }

+ 40 - 2
ActionTowerDefense/Assets/Scripts/Boss/YuMenGuan/YuMenGuan.cs

@@ -4,7 +4,7 @@ using UnityEngine;
 
 public class YuMenGuan : Boss
 {
-    public enum AttackType
+    public enum AttackMethods
     {
         move = 0,           //移动
         shockWave1 = 1,     //单手砸地,两侧冲击波
@@ -14,8 +14,46 @@ public class YuMenGuan : Boss
         blackHand = 5,      //黑手
     }
 
-    private void Move()
+    public enum AttackCategories
     {
+        A = 0,
+        B = 0,
+    }
+
+    [System.Serializable]
+    public struct AttackType
+    {
+        public AttackCategories category;
+        public AttackMethods[] attacks;
+    }
+
+    [Header("攻击配置")]
+    public AttackType[] attackConfigurations;
+
+    private void ToMove()
+    {
+        curTarget = TargetType.Tower;
+        CheckTarget();
         canMove = true;
     }
+
+    public override void OnMove()
+    {
+        if (!targetCharacter || targetCharacter.isDie)
+        {
+            CheckTarget();
+        }
+        if (Vector2.Distance(bodyTrans.position, targetCharacter.transform.position) <= 0.5f)
+        {
+            canMove = false;
+            rb.velocity = new Vector3(0, 0, 0);
+        }
+        Vector3 dir;
+        dir = bodyTrans.position.x <= targetCharacter.transform.position.x ? Vector3.right : Vector3.left;
+        if (dir.x * bodyTrans.localScale.x > 0)
+        {
+            Turn();
+        }
+        rb.velocity = dir * moveSpeed;
+    }
 }

+ 2 - 3
ActionTowerDefense/Assets/Scripts/Character.cs

@@ -359,13 +359,12 @@ public class Character : MonoBehaviour
     //ÌåÐͱä´ó
     public void Enlarge()
     {
-        transform.localScale = Vector3.SmoothDamp(transform.localScale, new Vector3(1, 1, 1) * toLargeSize, ref speed, 0.3f);
-        if (transform.localScale.x >= toLargeSize + 0.1f)
+        transform.localScale = Vector3.SmoothDamp(transform.localScale, new Vector3(1, 1, 1) * (toLargeSize + 0.1f), ref speed, 0.4f);
+        if (transform.localScale.x >= toLargeSize + 0.05f)
         {
             beLarger = false;
             transform.localScale = new Vector3(toLargeSize, toLargeSize, 1);
             toLargeSize = 0;
-            //print(transform.localScale);
         }
     }
 }