SZAND\msx_2 6 сар өмнө
parent
commit
df68f8d188

+ 13 - 3
ActionTowerDefense/Assets/Scripts/Characters/AttackController.cs

@@ -183,24 +183,31 @@ public class AttackController : MonoBehaviour
     {
         [Header("起手式id=0,行军式id>=1")]
         public int id;
-        [Header("攻击名称")]
+
+        [LabelText("攻击名称")]
         public string attackName;
-        [Header("攻击类型")]
+
+        [LabelText("攻击类型")]
         public AttackType attackType;
-        [Header("攻击特效")]
+
+        [LabelText("攻击特效")]
         public GameObject attackEffect;
+
         [Header("攻击参数")]
         public AttackInfo attackInfo;
         public AttackTrigger attackTrigger;
+
         [Header("攻击距离")]
         public float attackDistance;
         [ShowIf("needToChange")]
         public float maxAttackDis, minAttackDis;
         public bool needToChange;
+
         [Header("目标")]
         public List<TargetType> targetTypes;
         public bool canHitFly;
         public int armorPiercing;               //穿甲率
+
         [Header("远程单位")]
         [ShowIf("attackType",AttackType.Shoot)]
         public GameObject bulletPrefab;         //子弹
@@ -214,6 +221,7 @@ public class AttackController : MonoBehaviour
         public bool shootTrack;                 //是否初始时瞄准目标
         [ShowIf("attackType", AttackType.Shoot)]
         public bool shootAlwaysTrack;           //是否始终追踪
+
         [Header("特殊攻击")]
         [ShowIf("attackType", AttackType.Special)]
         public GameObject skillPrefab;
@@ -239,6 +247,8 @@ public class AttackController : MonoBehaviour
     public AttackType attackType;
 
     [Header("攻击参数")]
+    [LabelText("攻击间隔")]
+    public float attackInterval;
     [DisplayOnly]
     public int curDamage;
     [HideInInspector]

+ 111 - 85
ActionTowerDefense/Assets/Scripts/Characters/Demonic.cs

@@ -30,6 +30,7 @@ public class Demonic : MoveCharacter
     private int curAttackID;
     private AttackController.AttackMethod[] am;
     private int len;
+    private float pastAttackTime;
 
     [Header("°ËŘÔ")]
     public float adsorbSpeed;                           //°ËŘÔÎü¸˝ľÄËŮśČ
@@ -263,6 +264,7 @@ public class Demonic : MoveCharacter
         //hurtKeepTime -= Time.deltaTime;
         dieKeepTime -= Time.deltaTime;
         invincibleTime -= Time.deltaTime;
+        pastAttackTime += Time.deltaTime;
         Vector3 leftDir = GetMoveDir();
         bool isAttack = GetAttack();
 
@@ -276,129 +278,152 @@ public class Demonic : MoveCharacter
                 }
                 if (isAttack)
                 {
-                    Attack_march();
-                    break;
+                    if (pastAttackTime >= attackController.attackInterval)
+                    {
+                        Attack_march();
+                    }
                 }
-                if (!foot.TrigGround && !canFly)
+                else
                 {
-                    if (rb.velocity.y > 0)
+                    if (!foot.TrigGround && !canFly)
                     {
-                        ChangeState(CharacterState.Rise);
-                        break;
+                        if (rb.velocity.y > 0)
+                        {
+                            ChangeState(CharacterState.Rise);
+                            break;
+                        }
+                        else
+                        {
+                            ChangeState(CharacterState.Fall);
+                            break;
+                        }
                     }
-                    else
+                    if (leftDir.x > 0.3f || leftDir.x < -0.3f)
                     {
-                        ChangeState(CharacterState.Fall);
+                        ChangeState(CharacterState.Run);
                         break;
                     }
+                    rb.velocity = Vector3.right * velocityAddition;
                 }
-                if (leftDir.x > 0.3f || leftDir.x < -0.3f)
-                {
-                    ChangeState(CharacterState.Run);
-                    break;
-                }
-                rb.velocity = Vector3.right * velocityAddition;
                 break;
             case CharacterState.Run:
                 if (isAttack)
                 {
-                    Attack_march();
-                    break;
-                }
-                if (!foot.TrigGround && !canFly)
-                {
-                    if (rb.velocity.y > 0)
+                    if (pastAttackTime >= attackController.attackInterval)
                     {
-                        ChangeState(CharacterState.Rise);
-                        break;
+                        Attack_march();
                     }
                     else
                     {
-                        ChangeState(CharacterState.Fall);
-                        break;
+                        ChangeState(CharacterState.Idle);
                     }
                 }
-                if (leftDir.x < 0.3f && leftDir.x > -0.3f)
-                {
-                    ChangeState(CharacterState.Idle);
-                    break;
-                }
-                if (leftDir.x > 0.3f)
+                else
                 {
-                    //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.right * (moveSpeed + velocityAddition);
-                    //if (rb.velocity.x > maxMoveSpeed)
-                    //{
-                    //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                    //}
-                    if (bodyTrans.localScale.x > 0)
+                    if (!foot.TrigGround && !canFly)
                     {
-                        Turn();
+                        if (rb.velocity.y > 0)
+                        {
+                            ChangeState(CharacterState.Rise);
+                            break;
+                        }
+                        else
+                        {
+                            ChangeState(CharacterState.Fall);
+                            break;
+                        }
                     }
-                }
-                else if (leftDir.x < -0.3f)
-                {
-                    //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.right * (-moveSpeed + velocityAddition);
-                    //if (rb.velocity.x < -maxMoveSpeed)
-                    //{
-                    //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                    //}
-                    if (bodyTrans.localScale.x < 0)
+                    if (leftDir.x < 0.3f && leftDir.x > -0.3f)
                     {
-                        Turn();
+                        ChangeState(CharacterState.Idle);
+                        break;
                     }
+                    if (leftDir.x > 0.3f)
+                    {
+                        //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
+                        rb.velocity = Vector3.right * (moveSpeed + velocityAddition);
+                        //if (rb.velocity.x > maxMoveSpeed)
+                        //{
+                        //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
+                        //}
+                        if (bodyTrans.localScale.x > 0)
+                        {
+                            Turn();
+                        }
+                    }
+                    else if (leftDir.x < -0.3f)
+                    {
+                        //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
+                        rb.velocity = Vector3.right * (-moveSpeed + velocityAddition);
+                        //if (rb.velocity.x < -maxMoveSpeed)
+                        //{
+                        //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
+                        //}
+                        if (bodyTrans.localScale.x < 0)
+                        {
+                            Turn();
+                        }
+                    }
+                    AdjustHeight();
                 }
-                AdjustHeight();
                 break;
             case CharacterState.Rush:
                 if (isAttack)
                 {
-                    Attack_march();
-                    break;
-                }
-                if (!foot.TrigGround && !canFly)
-                {
-                    if (rb.velocity.y > 0)
+                    if (pastAttackTime >= attackController.attackInterval)
                     {
-                        ChangeState(CharacterState.Rise);
-                        break;
+                        Attack_march();
                     }
                     else
                     {
-                        ChangeState(CharacterState.Fall);
-                        break;
+                        ChangeState(CharacterState.Idle);
                     }
                 }
-                if (leftDir.x < 0.3f && leftDir.x > -0.3f)
-                {
-                    ChangeState(CharacterState.Idle);
-                    break;
-                }
-                if (leftDir.x > 0.3f)
+                else
                 {
-                    //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.right * runSpeed;
-                    //if (rb.velocity.x > maxMoveSpeed)
-                    //{
-                    //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                    //}
-                    if (bodyTrans.localScale.x > 0)
+                    if (!foot.TrigGround && !canFly)
                     {
-                        Turn();
+                        if (rb.velocity.y > 0)
+                        {
+                            ChangeState(CharacterState.Rise);
+                            break;
+                        }
+                        else
+                        {
+                            ChangeState(CharacterState.Fall);
+                            break;
+                        }
                     }
-                }
-                else if (leftDir.x < -0.3f)
-                {
-                    //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.left * runSpeed;
-                    //if (rb.velocity.x < -maxMoveSpeed)
-                    //{
-                    //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                    //}
-                    if (bodyTrans.localScale.x < 0)
+                    if (leftDir.x < 0.3f && leftDir.x > -0.3f)
                     {
-                        Turn();
+                        ChangeState(CharacterState.Idle);
+                        break;
+                    }
+                    if (leftDir.x > 0.3f)
+                    {
+                        //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
+                        rb.velocity = Vector3.right * runSpeed;
+                        //if (rb.velocity.x > maxMoveSpeed)
+                        //{
+                        //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
+                        //}
+                        if (bodyTrans.localScale.x > 0)
+                        {
+                            Turn();
+                        }
+                    }
+                    else if (leftDir.x < -0.3f)
+                    {
+                        //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
+                        rb.velocity = Vector3.left * runSpeed;
+                        //if (rb.velocity.x < -maxMoveSpeed)
+                        //{
+                        //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
+                        //}
+                        if (bodyTrans.localScale.x < 0)
+                        {
+                            Turn();
+                        }
                     }
                 }
                 break;
@@ -698,6 +723,7 @@ public class Demonic : MoveCharacter
             curAttackID = 0;
         }
         attackTarget = targetCharacter;
+        pastAttackTime = 0;
     }
 
     public void DropSouls()

+ 100 - 74
ActionTowerDefense/Assets/Scripts/Characters/Enemy.cs

@@ -57,6 +57,7 @@ public class Enemy : MoveCharacter
     private int curAttackID;
     private AttackController.AttackMethod[] am;
     private int len;
+    private float pastAttackTime;
 
     [Header("ľôÂäťę")]
     public int dropSoulMax = 3;
@@ -203,6 +204,7 @@ public class Enemy : MoveCharacter
         //hurtKeepTime -= Time.deltaTime;
         dieKeepTime -= Time.deltaTime;
         invincibleTime -= Time.deltaTime;
+        pastAttackTime += Time.deltaTime;
         Vector3 leftDir = GetMoveDir();
         bool isAttack = GetAttack();
 
@@ -216,120 +218,143 @@ public class Enemy : MoveCharacter
                 }
                 if (isAttack)
                 {
-                    Attack_march();
-                    break;
+                    if (pastAttackTime >= attackController.attackInterval)
+                    {
+                        Attack_march();
+                    }
                 }
-                if (!foot.TrigGround && !canFly)
+                else
                 {
-                    if (rb.velocity.y > 0)
+                    if (!foot.TrigGround && !canFly)
                     {
-                        ChangeState(CharacterState.Rise);
-                        break;
+                        if (rb.velocity.y > 0)
+                        {
+                            ChangeState(CharacterState.Rise);
+                            break;
+                        }
+                        else
+                        {
+                            ChangeState(CharacterState.Fall);
+                            break;
+                        }
                     }
-                    else
+                    if (leftDir.x > 0.3f || leftDir.x < -0.3f)
                     {
-                        ChangeState(CharacterState.Fall);
+                        ChangeState(CharacterState.Run);
                         break;
                     }
                 }
-                if (leftDir.x > 0.3f || leftDir.x < -0.3f)
-                {
-                    ChangeState(CharacterState.Run);
-                    break;
-                }
                 break;
             case CharacterState.Run:
                 if (isAttack)
                 {
-                    Attack_march();
-                    break;
-                }
-                if (!foot.TrigGround && !canFly)
-                {
-                    if (rb.velocity.y > 0)
+                    if (pastAttackTime >= attackController.attackInterval)
                     {
-                        ChangeState(CharacterState.Rise);
-                        break;
+                        Attack_march();
                     }
                     else
                     {
-                        ChangeState(CharacterState.Fall);
-                        break;
+                        ChangeState(CharacterState.Idle);
                     }
                 }
-                if (leftDir.x < 0.3f && leftDir.x > -0.3f)
-                {
-                    ChangeState(CharacterState.Idle);
-                    break;
-                }
-                if (leftDir.x > 0.3f)
+                else
                 {
-                    rb.velocity = Vector3.right * moveSpeed;
-                    if (bodyTrans.localScale.x > 0)
+                    if (!foot.TrigGround && !canFly)
                     {
-                        Turn();
+                        if (rb.velocity.y > 0)
+                        {
+                            ChangeState(CharacterState.Rise);
+                            break;
+                        }
+                        else
+                        {
+                            ChangeState(CharacterState.Fall);
+                            break;
+                        }
                     }
-                }
-                else if (leftDir.x < -0.3f)
-                {
-                    rb.velocity = Vector3.left * moveSpeed;
-                    if (bodyTrans.localScale.x < 0)
+                    if (leftDir.x < 0.3f && leftDir.x > -0.3f)
                     {
-                        Turn();
+                        ChangeState(CharacterState.Idle);
+                        break;
+                    }
+                    if (leftDir.x > 0.3f)
+                    {
+                        rb.velocity = Vector3.right * moveSpeed;
+                        if (bodyTrans.localScale.x > 0)
+                        {
+                            Turn();
+                        }
+                    }
+                    else if (leftDir.x < -0.3f)
+                    {
+                        rb.velocity = Vector3.left * moveSpeed;
+                        if (bodyTrans.localScale.x < 0)
+                        {
+                            Turn();
+                        }
                     }
                 }
                 break;
             case CharacterState.Rush:
                 if (isAttack)
                 {
-                    Attack_march();
-                    break;
-                }
-                if (!foot.TrigGround && !canFly)
-                {
-                    if (rb.velocity.y > 0)
+                    if (pastAttackTime >= attackController.attackInterval)
                     {
-                        ChangeState(CharacterState.Rise);
-                        break;
+                        Attack_march();
                     }
                     else
                     {
-                        ChangeState(CharacterState.Fall);
-                        break;
+                        ChangeState(CharacterState.Idle);
                     }
                 }
-                if (leftDir.x < 0.3f && leftDir.x > -0.3f)
-                {
-                    ChangeState(CharacterState.Idle);
-                    break;
-                }
-                if (leftDir.x > 0.3f)
+                else
                 {
-                    //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.right * runSpeed;
-                    //if (rb.velocity.x > maxMoveSpeed)
-                    //{
-                    //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                    //}
-                    if (bodyTrans.localScale.x > 0)
+                    if (!foot.TrigGround && !canFly)
                     {
-                        Turn();
+                        if (rb.velocity.y > 0)
+                        {
+                            ChangeState(CharacterState.Rise);
+                            break;
+                        }
+                        else
+                        {
+                            ChangeState(CharacterState.Attack);
+                            break;
+                        }
                     }
-                }
-                else if (leftDir.x < -0.3f)
-                {
-                    //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
-                    rb.velocity = Vector3.left * runSpeed;
-                    //if (rb.velocity.x < -maxMoveSpeed)
-                    //{
-                    //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                    //}
-                    if (bodyTrans.localScale.x < 0)
+                    if (leftDir.x < 0.3f && leftDir.x > -0.3f)
                     {
-                        Turn();
+                        ChangeState(CharacterState.Idle);
+                        break;
+                    }
+                    if (leftDir.x > 0.3f)
+                    {
+                        //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
+                        rb.velocity = Vector3.right * runSpeed;
+                        //if (rb.velocity.x > maxMoveSpeed)
+                        //{
+                        //    rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
+                        //}
+                        if (bodyTrans.localScale.x > 0)
+                        {
+                            Turn();
+                        }
+                    }
+                    else if (leftDir.x < -0.3f)
+                    {
+                        //rb.velocity -= Vector3.right * moveAcc * Time.deltaTime;
+                        rb.velocity = Vector3.left * runSpeed;
+                        //if (rb.velocity.x < -maxMoveSpeed)
+                        //{
+                        //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
+                        //}
+                        if (bodyTrans.localScale.x < 0)
+                        {
+                            Turn();
+                        }
                     }
+                    //AdjustHeight();
                 }
-                //AdjustHeight();
                 break;
             case CharacterState.Rise:
                 if (isAdjustHeight == 1)
@@ -675,6 +700,7 @@ public class Enemy : MoveCharacter
             curAttackID = 0;
         }
         attackTarget = targetCharacter;
+        pastAttackTime = 0;
     }
 
     public void ChosePlayer()