Parcourir la source

dash可以选择方向随便飞

wulifu il y a 1 an
Parent
commit
5fc8d16749
1 fichiers modifiés avec 35 ajouts et 17 suppressions
  1. 35 17
      ActionTowerDefense/Assets/Scripts/PlayerController.cs

+ 35 - 17
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -80,6 +80,7 @@ public class PlayerController : MoveCharacter
     public PlayerAttackState attackState;
     public float attackMoveSpeed = 5f;
     public Enemy lastLinkedEnemy;
+    public Vector3 rushDir;
 
     public bool btnJumpPress
     {
@@ -726,14 +727,22 @@ public class PlayerController : MoveCharacter
                     }
                 }
                 CachedPlayerInput();
-                if (bodyTrans.localScale.x > 0)
+                if (leftDir.magnitude < 0.3f)
                 {
-                    rb.velocity = Vector3.left * rushSpeed;
+                    if (bodyTrans.localScale.x > 0)
+                    {
+                        rushDir = Vector3.left;
+                    }
+                    else
+                    {
+                        rushDir = Vector3.right;
+                    }
                 }
                 else
                 {
-                    rb.velocity = Vector3.right * rushSpeed;
+                    rushDir = leftDir.normalized;
                 }
+                rb.velocity = rushDir * rushSpeed;
                 break;
             case CharacterState.Sprint:
                 if (!btnRushKeep)
@@ -754,14 +763,22 @@ public class PlayerController : MoveCharacter
                 uiMp.Show(mp, totalMp);
                 CachedPlayerInput();
                 CheckTurn();
-                if (bodyTrans.localScale.x > 0)
+                if (leftDir.magnitude < 0.3f)
                 {
-                    rb.velocity = Vector3.left * rushSpeed;
+                    if (bodyTrans.localScale.x > 0)
+                    {
+                        rushDir = Vector3.left;
+                    }
+                    else
+                    {
+                        rushDir = Vector3.right;
+                    }
                 }
                 else
                 {
-                    rb.velocity = Vector3.right * rushSpeed;
+                    rushDir = leftDir.normalized;
                 }
+                rb.velocity = rushDir * rushSpeed;
                 break;
             case CharacterState.Die:
                 if (dieKeepTime <= 0)
@@ -913,28 +930,29 @@ public class PlayerController : MoveCharacter
                 ani.Play("rush_loop", 0, 0);
                 rushTime = totalRushTime;
                 invincibleTime = rushInvincibleTime;
-                if (bodyTrans.localScale.x > 0)
+                if (leftDir.magnitude < 0.3f)
                 {
-                    velocity = Vector3.left * rushSpeed;
+                    if (bodyTrans.localScale.x > 0)
+                    {
+                        rushDir = Vector3.left;
+                    }
+                    else
+                    {
+                        rushDir = Vector3.right;
+                    }
                 }
                 else
                 {
-                    velocity = Vector3.right * rushSpeed;
+                    rushDir = leftDir.normalized;
                 }
+                velocity = rushDir * rushSpeed;
                 mp -= rushCostMp;
                 uiMp.Show(mp, totalMp);
                 break;
             case CharacterState.Sprint:
                 aniCollider.Play("Sprint", 0, 0);
                 ani.Play("rush_loop", 0, 0);
-                if (bodyTrans.localScale.x > 0)
-                {
-                    velocity = Vector3.left * rushSpeed;
-                }
-                else
-                {
-                    velocity = Vector3.right * rushSpeed;
-                }
+                velocity = rushDir * rushSpeed;
                 break;
             case CharacterState.Die:
                 aniCollider.Play("Die", 0, 0);