Jelajahi Sumber

击落后飞回原高度

wgl 6 bulan lalu
induk
melakukan
2a31ee2767

+ 2 - 3
ActionTowerDefense/Assets/Scripts/Characters/AttributeStatus.cs

@@ -7,7 +7,7 @@ using UnityEngine;
 public class AttributeStatus : MonoBehaviour
 {
     //×é¼þ
-    private Character character;
+    private MoveCharacter character;
     private Rigidbody rb;
     private Foot foot; 
 
@@ -32,7 +32,7 @@ public class AttributeStatus : MonoBehaviour
 
     private void Awake()
     {
-        character = GetComponent<Character>();
+        character = GetComponent<MoveCharacter>();
         rb = GetComponent<Rigidbody>();
         foot = GetComponentInChildren<Foot>();
     }
@@ -96,7 +96,6 @@ public class AttributeStatus : MonoBehaviour
                         {
                             character.ChangeState(CharacterState.Idle);
                         }
-                        character.ChangeState(CharacterState.Idle);
                     }
                     else
                     {

+ 2 - 50
ActionTowerDefense/Assets/Scripts/Characters/Demonic.cs

@@ -12,8 +12,6 @@ public class Demonic : MoveCharacter
     public int id;
     public float costMp = 10;
     public bool isBack = false;         //往反方向走
-    public float flyHeight;
-    public float flyUpSpeed = 10;
     public int baseSortingOrder;
     int sortingOrder = 0;
     public float runSpeed;
@@ -45,12 +43,6 @@ public class Demonic : MoveCharacter
     public int dropSoulMax = 3;
     public int dropSoulMin = 1;
     public float dropSoulAngle = 60f;
-
-    [Header("验证功能开关")]
-    public bool upFirstAfterWeaknessOrNot;  //虚弱结束后是否先升高
-
-    public bool isBeBlownUp;    //被击飞
-
     private void Start()
     {
         if (needToChange)
@@ -255,28 +247,6 @@ public class Demonic : MoveCharacter
         return false;
     }
 
-    public override bool AdjustHeight()
-    {
-        if (canFly)
-        {
-            if (transform.position.y - flyHeight > 0.1f)
-            {
-                Vector3 pos = transform.position;
-                pos.y -= flyUpSpeed * Time.deltaTime;
-                transform.position = pos;
-                return false;
-            }
-            else if (transform.position.y - flyHeight < -0.1f)
-            {
-                Vector3 pos = transform.position;
-                pos.y += flyUpSpeed * Time.deltaTime;
-                transform.position = pos;
-                return false;
-            }
-        }
-        return true;
-    }
-
     public override void OnState()
     {
         base.OnState();
@@ -314,16 +284,7 @@ public class Demonic : MoveCharacter
                     ChangeState(CharacterState.Run);
                     break;
                 }
-
-                if (!upFirstAfterWeaknessOrNot)
-                {
-                    if (canFly)
-                    {
-                        rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
-                        rb.useGravity = false;
-                        AdjustHeight();
-                    }
-                }
+                AdjustHeight();
                 rb.velocity = Vector3.right * velocityAddition;
                 break;
             case CharacterState.Run:
@@ -376,15 +337,7 @@ public class Demonic : MoveCharacter
                         Turn();
                     }
                 }
-                if (!upFirstAfterWeaknessOrNot)
-                {
-                    if (canFly)
-                    {
-                        rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
-                        rb.useGravity = false;
-                        AdjustHeight();
-                    }
-                }
+                AdjustHeight();
                 break;
             case CharacterState.Rush:
                 if (isAttack)
@@ -436,7 +389,6 @@ public class Demonic : MoveCharacter
                         Turn();
                     }
                 }
-                //AdjustHeight();
                 break;
             case CharacterState.Rise:
                 if (rb.velocity.y <= 0)

+ 0 - 48
ActionTowerDefense/Assets/Scripts/Characters/Enemy.cs

@@ -32,8 +32,6 @@ public class Enemy : MoveCharacter
     public int baseSortingOrder;
     int sortingOrder = 0;
     public bool isBack = false; //往反方向走
-    public float flyHeight;
-    public float flyUpSpeed = 10;
     public float jumpSpeed = 10;
     public float maxMoveSpeed, minMoveSpeed;
     public float runSpeed;
@@ -73,9 +71,6 @@ public class Enemy : MoveCharacter
     public int dropSoulMin = 1;
     public float dropSoulAngle = 60f;
 
-    [Header("验证功能开关")]
-    public bool upFirstAfterWeaknessOrNot;  //虚弱结束后是否先升高
-
     private void Start()
     {
         if (needToChange)
@@ -215,28 +210,6 @@ public class Enemy : MoveCharacter
         return false;
     }
 
-    public bool AdjustHeight()
-    {
-        if (canFly)
-        {
-            if (transform.position.y - flyHeight > 0.1f)
-            {
-                Vector3 pos = transform.position;
-                pos.y -= flyUpSpeed * Time.deltaTime;
-                transform.position = pos;
-                return false;
-            }
-            else if (transform.position.y - flyHeight < -0.1f)
-            {
-                Vector3 pos = transform.position;
-                pos.y += flyUpSpeed * Time.deltaTime;
-                transform.position = pos;
-                return false;
-            }
-        }
-        return true;
-    }
-
     public override void OnState()
     {
         base.OnState();
@@ -274,17 +247,6 @@ public class Enemy : MoveCharacter
                     ChangeState(CharacterState.Run);
                     break;
                 }
-                //rb.velocity = Vector3.zero;
-                if (!upFirstAfterWeaknessOrNot)
-                {
-                    if (canFly)
-                    {
-                        rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
-                        rb.useGravity = false;
-                        AdjustHeight();
-                    }
-                }
-
                 break;
             case CharacterState.Run:
                 if (isAttack)
@@ -326,16 +288,6 @@ public class Enemy : MoveCharacter
                         Turn();
                     }
                 }
-                if (!upFirstAfterWeaknessOrNot)
-                {
-                    if (canFly)
-                    {
-                        rb.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY;
-                        rb.useGravity = false;
-                        AdjustHeight();
-                    }
-
-                }
                 break;
             case CharacterState.Rush:
                 if (isAttack)

+ 24 - 0
ActionTowerDefense/Assets/Scripts/Characters/MoveCharacter.cs

@@ -28,6 +28,8 @@ public class MoveCharacter : Character
     [Header("ÊôÐÔ")]
     public bool canMove = true;
     public float moveSpeed = 5;
+    public float flyHeight;
+    public float flyUpSpeed = 10;
 
     [Header("ÐéÈõ״̬")]
     public float totalBeRepelValue;
@@ -570,4 +572,26 @@ public class MoveCharacter : Character
             BeHit(sustainedInjury_damage, Vector3.zero,false,0);
         }
     }
+
+    public override bool AdjustHeight()
+    {
+        if (canFly)
+        {
+            if (transform.position.y - flyHeight > 0.1f)
+            {
+                Vector3 pos = transform.position;
+                pos.y -= flyUpSpeed * Time.deltaTime;
+                transform.position = pos;
+                return false;
+            }
+            else if (transform.position.y - flyHeight < -0.1f)
+            {
+                Vector3 pos = transform.position;
+                pos.y += flyUpSpeed * Time.deltaTime;
+                transform.position = pos;
+                return false;
+            }
+        }
+        return true;
+    }
 }