Bladeren bron

增加二段跳

wulifu 1 jaar geleden
bovenliggende
commit
e7317759b2

+ 4 - 0
ActionTowerDefense/Assets/Scenes/SampleScene.unity

@@ -863,6 +863,10 @@ PrefabInstance:
   m_Modification:
     m_TransformParent: {fileID: 0}
     m_Modifications:
+    - target: {fileID: 3571941038519084336, guid: 5b538f610930dd743a096c582e2810f4, type: 3}
+      propertyPath: airJumpSpeed
+      value: 20
+      objectReference: {fileID: 0}
     - target: {fileID: 3571941038519084336, guid: 5b538f610930dd743a096c582e2810f4, type: 3}
       propertyPath: totalRushTime
       value: 0.2

+ 33 - 24
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -37,7 +37,7 @@ public class PlayerController : MonoBehaviour
     public float extraRiseGravity = 0; //上升时额外重力加速度
     public float extraFallGravity = -10; //下落时额外重力加速度
     public float jumpSpeed = 10;
-    //public float airJumpSpeed = 10;
+    public float airJumpSpeed = 10;
     public float maxMoveSpeed = 5;
     //public float moveAcc = 5f;
     //public float airMoveAcc = 3f;
@@ -76,6 +76,8 @@ public class PlayerController : MonoBehaviour
     [HideInInspector]
     public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
     public float totalCacheRushTime = 0.1f;
+    [HideInInspector]
+    public bool airJumped;
 
     public bool isDie = false;
 
@@ -201,6 +203,12 @@ public class PlayerController : MonoBehaviour
         ani.Play("jump", 0, 0);
     }
 
+    public void AirJump()
+    {
+        SetUpSpeed(airJumpSpeed);
+        ani.Play("jump", 0, 0);
+    }
+
     public void SetUpSpeed(float speed)
     {
         ChangeState(PlayerState.Rise);
@@ -394,15 +402,15 @@ public class PlayerController : MonoBehaviour
                     ChangeState(PlayerState.Fall);
                     break;
                 }
-                //if (btnJumpPress || cacheJumpTime > 0)
-                //{
-                //    if (!airJumped && rb.velocity.y < airJumpSpeed)
-                //    {
-                //        airJumped = true;
-                //        AirJump();
-                //        break;
-                //    }
-                //}
+                if (btnJumpPress || cacheJumpTime > 0)
+                {
+                    if (!airJumped && rb.velocity.y < airJumpSpeed)
+                    {
+                        airJumped = true;
+                        AirJump();
+                        break;
+                    }
+                }
                 if (btnRushPress)
                 {
                     cacheRushTime = totalCacheRushTime;
@@ -456,20 +464,20 @@ public class PlayerController : MonoBehaviour
                 //    StepEnemy();
                 //    break;
                 //}
-                //if (btnJumpPress || cacheJumpTime > 0)
-                //{
-                //    if (!airJumped)
-                //    {
-                //        airJumped = true;
-                //        AirJump();
-                //        break;
-                //    }
-                //    else if (canJumpTick >= runner.Tick)
-                //    {
-                //        Jump();
-                //        break;
-                //    }
-                //}
+                if (btnJumpPress || cacheJumpTime > 0)
+                {
+                    if (!airJumped)
+                    {
+                        airJumped = true;
+                        AirJump();
+                        break;
+                    }
+                    else if (cacheJumpTime > 0)
+                    {
+                        Jump();
+                        break;
+                    }
+                }
                 if (btnRushPress)
                 {
                     cacheRushTime = totalCacheRushTime;
@@ -797,4 +805,5 @@ public class PlayerController : MonoBehaviour
         }
         demonic.ChangeState(DemonicState.Attack1);
     }
+
 }