Explorar o código

弓箭手现在眩晕了能做一个掉下来的功能吗?眩晕时间结束再回到原来的高度

wulifu hai 1 ano
pai
achega
0b95391eaf

+ 32 - 0
ActionTowerDefense/Assets/Scripts/Demonic.cs

@@ -11,6 +11,8 @@ public class Demonic : MoveCharacter
     public SearchState searchState;
     public float attackDistance;
     public bool canFly = false;
+    public float flyHeight;
+    public float flyUpSpeed = 10;
     public int sortingOrder = 0;
 
     public int playerID;
@@ -185,6 +187,25 @@ public class Demonic : MoveCharacter
         return false;
     }
 
+    public void AdjustHeight()
+    {
+        if (canFly)
+        {
+            if (transform.position.y - flyHeight > 0.1f)
+            {
+                Vector3 pos = transform.position;
+                pos.y -= flyUpSpeed * Time.deltaTime;
+                transform.position = pos;
+            }
+            else if (transform.position.y - flyHeight < -0.1f)
+            {
+                Vector3 pos = transform.position;
+                pos.y += flyUpSpeed * Time.deltaTime;
+                transform.position = pos;
+            }
+        }
+    }
+
     public override void OnState()
     {
         base.OnState();
@@ -195,6 +216,7 @@ public class Demonic : MoveCharacter
         weakTime -= Time.deltaTime;
         Vector3 leftDir = GetMoveDir();
         bool isAttack = GetAttack();
+        
         switch (state)
         {
             case CharacterState.Idle:
@@ -221,6 +243,7 @@ public class Demonic : MoveCharacter
                     ChangeState(CharacterState.Run);
                     break;
                 }
+                AdjustHeight();
                 //rb.velocity = Vector3.zero;
                 break;
             case CharacterState.Run:
@@ -273,6 +296,7 @@ public class Demonic : MoveCharacter
                         Turn();
                     }
                 }
+                AdjustHeight();
                 break;
             case CharacterState.Rise:
                 if (rb.velocity.y <= 0)
@@ -390,6 +414,10 @@ public class Demonic : MoveCharacter
                 isDie = false;
                 break;
             case CharacterState.Weak:
+                if (canFly)
+                {
+                    rb.constraints += 4; //RigidbodyConstraints.FreezePositionY = 4£¬²»ÄÜÖ±½Ó¼Ó
+                }
                 break;
             default:
                 break;
@@ -443,6 +471,10 @@ public class Demonic : MoveCharacter
                 velocity.y = weakUpSpeed;
                 rb.velocity = velocity;
                 weakTime = totalWeakTime;
+                if (canFly)
+                {
+                    rb.constraints -= RigidbodyConstraints.FreezePositionY;
+                }
                 break;
             default:
                 break;

+ 24 - 0
ActionTowerDefense/Assets/Scripts/Enemy.cs

@@ -30,6 +30,8 @@ public class Enemy : MoveCharacter
     public SearchState searchState;
     public float attackDistance;
     public bool canFly = false;
+    public float flyHeight;
+    public float flyUpSpeed = 10;
 
     public float attackRatio;
     public float maxMoveSpeed, minMoveSpeed;
@@ -130,6 +132,25 @@ public class Enemy : MoveCharacter
         return false;
     }
 
+    public void AdjustHeight()
+    {
+        if (canFly)
+        {
+            if (transform.position.y - flyHeight > 0.1f)
+            {
+                Vector3 pos = transform.position;
+                pos.y -= flyUpSpeed * Time.deltaTime;
+                transform.position = pos;
+            }
+            else if (transform.position.y - flyHeight < -0.1f)
+            {
+                Vector3 pos = transform.position;
+                pos.y += flyUpSpeed * Time.deltaTime;
+                transform.position = pos;
+            }
+        }
+    }
+
     public override void OnState()
     {
         base.OnState();
@@ -140,6 +161,7 @@ public class Enemy : MoveCharacter
         weakTime -= Time.deltaTime;
         Vector3 leftDir = GetMoveDir();
         bool isAttack = GetAttack();
+        
         switch (state)
         {
             case CharacterState.Idle:
@@ -167,6 +189,7 @@ public class Enemy : MoveCharacter
                     break;
                 }
                 //rb.velocity = Vector3.zero;
+                AdjustHeight();
                 break;
             case CharacterState.Run:
                 if (isAttack)
@@ -218,6 +241,7 @@ public class Enemy : MoveCharacter
                         Turn();
                     }
                 }
+                AdjustHeight();
                 break;
             case CharacterState.Rise:
                 if (rb.velocity.y <= 0)

+ 4 - 0
ActionTowerDefense/Assets/Scripts/EnemyCreater.cs

@@ -87,6 +87,10 @@ public class EnemyCreater : MonoBehaviour
             attackInfo.damage = (int)(cfgEnemy.Attack2[i] * attackRatio);
             enemy.attack2Infos[i] = attackInfo;
         }
+        if (enemy.canFly)
+        {
+            enemy.flyHeight = enemy.transform.position.y;
+        }
         enemy.Init();
         enemy.SetSortingOrder(cfgEnemy.SortingOrder + enemyDic[enemyId].Count);
     }

+ 5 - 0
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -1278,6 +1278,11 @@ public class PlayerController : MoveCharacter
                 demonic.Turn();
             }
         }
+        if (demonic.canFly)
+        {
+            demonic.flyHeight = demonic.transform.position.y;
+        }
+
         if (id == 3)
         {
             if ((int)spirits.currentSpirit == 0)