Selaa lähdekoodia

"DASH要改为,按住某个键可以一直“飞”,然后冲的过程中用摇杆控制“飞”的方向,飞行功能有一个初始的dash效果。(用来解决飞行敌人和攻击巨型敌人的弱点)"

wulifu 1 vuosi sitten
vanhempi
commit
d43e607584

+ 1 - 1
ActionTowerDefense/Assets/Resources/Spine/king_devil/king_deil_Controller.controller

@@ -1408,7 +1408,7 @@ AnimationClip:
     m_Level: 0
     m_CycleOffset: 0
     m_HasAdditiveReferencePose: 0
-    m_LoopTime: 0
+    m_LoopTime: 1
     m_LoopBlend: 0
     m_LoopBlendOrientation: 0
     m_LoopBlendPositionY: 0

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

@@ -1047,6 +1047,10 @@ PrefabInstance:
   m_Modification:
     m_TransformParent: {fileID: 0}
     m_Modifications:
+    - target: {fileID: 3571941038519084336, guid: 5b538f610930dd743a096c582e2810f4, type: 3}
+      propertyPath: rushInvincibleTime
+      value: 0.2
+      objectReference: {fileID: 0}
     - target: {fileID: 3571941038519084344, guid: 5b538f610930dd743a096c582e2810f4, type: 3}
       propertyPath: m_Name
       value: Player

+ 2 - 1
ActionTowerDefense/Assets/Scripts/Character.cs

@@ -15,7 +15,8 @@ public enum CharacterState
     Attack = 6,
     Summon = 7,
     Rush = 8,
-    Die = 9,
+    Sprint = 9,
+    Die = 10,
 }
 
 public enum AttackType

+ 91 - 53
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -37,6 +37,7 @@ public class PlayerController : MoveCharacter
     [HideInInspector]
     public float invincibleTime;
     public float totalInvincibleTime = 2f;
+    public float rushInvincibleTime = 0.2f;
     [HideInInspector]
     public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
     public float leaveGroundCanJumpTime = 0.1f;
@@ -76,11 +77,20 @@ public class PlayerController : MoveCharacter
     {
         get
         {
-            return Input.GetKey(KeyCode.LeftShift) || isClickBtnRush;
+            return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
         }
     }
     [HideInInspector]
     public bool isClickBtnRush;
+    public bool btnRushKeep
+    {
+        get
+        {
+            return Input.GetKey(KeyCode.LeftShift) || isKeepBtnRush;
+        }
+    }
+    [HideInInspector]
+    public bool isKeepBtnRush;
     public bool btnSouthPress
     {
         get
@@ -165,6 +175,10 @@ public class PlayerController : MoveCharacter
         {
             isClickBtnRush = true;
         }
+        if (Input.GetKey(KeyCode.LeftShift))
+        {
+            isKeepBtnRush = true;
+        }
         if (Input.GetKeyDown(KeyCode.Space))
         {
             isClickBtnJump = true;
@@ -208,20 +222,7 @@ public class PlayerController : MoveCharacter
     {
         ChangeState(CharacterState.Rise);
         Vector3 velocity = rb.velocity;
-        if (leftDir.x > 0.3f)
-        {
-            if (bodyTrans.localScale.x > 0)
-            {
-                Turn();
-            }
-        }
-        else if (leftDir.x < -0.3f)
-        {
-            if (bodyTrans.localScale.x < 0)
-            {
-                Turn();
-            }
-        }
+        CheckTurn();
         velocity.y = speed;
         rb.velocity = velocity;
         //animalAni.SetInteger("state", (int)PlayerState.Rise);
@@ -232,6 +233,14 @@ public class PlayerController : MoveCharacter
     {
         if (!foot.TrigGround)
         {
+            if (btnRushPress || cacheRushTime > 0)
+            {
+                if (excludeState != CharacterState.Rush)
+                {
+                    ChangeState(CharacterState.Rush);
+                    return true;
+                }
+            }
             if (rb.velocity.y > 0)
             {
                 if (excludeState != CharacterState.Rise)
@@ -399,31 +408,14 @@ public class PlayerController : MoveCharacter
                     break;
                 }
                 canJumpTime = leaveGroundCanJumpTime;
+                CheckTurn();
                 if (leftDir.x > 0.3f)
                 {
-                    //rb.velocity += Vector3.right * moveAcc * Time.deltaTime;
                     rb.velocity = Vector3.right * maxMoveSpeed;
-                    //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 * maxMoveSpeed;
-                    //if (rb.velocity.x < -maxMoveSpeed)
-                    //{
-                    //    rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-                    //}
-                    if (bodyTrans.localScale.x < 0)
-                    {
-                        Turn();
-                    }
                 }
                 break;
             case CharacterState.Rise:
@@ -531,6 +523,11 @@ public class PlayerController : MoveCharacter
             case CharacterState.Rush:
                 if (rushTime <= 0)
                 {
+                    if (btnRushKeep)
+                    {
+                        ChangeState(CharacterState.Sprint);
+                        break;
+                    }
                     if (CheckPlayerChangeState())
                     {
                         break;
@@ -546,6 +543,25 @@ public class PlayerController : MoveCharacter
                     rb.velocity = Vector3.right * rushSpeed;
                 }
                 break;
+            case CharacterState.Sprint:
+                if (!btnRushKeep)
+                {
+                    if (CheckPlayerChangeState(CharacterState.Rush))
+                    {
+                        break;
+                    }
+                }
+                CachedPlayerInput();
+                CheckTurn();
+                if (bodyTrans.localScale.x > 0)
+                {
+                    rb.velocity = Vector3.left * rushSpeed;
+                }
+                else
+                {
+                    rb.velocity = Vector3.right * rushSpeed;
+                }
+                break;
             case CharacterState.Die:
                 if (dieKeepTime <= 0)
                 {
@@ -557,6 +573,7 @@ public class PlayerController : MoveCharacter
                 break;
         }
         isClickBtnRush = false;
+        isKeepBtnRush = false;
         isClickBtnJump = false;
         isClickBtnSouth = false;
         isClickBtnEast = false;
@@ -566,6 +583,7 @@ public class PlayerController : MoveCharacter
 
     public override void ChangeState(CharacterState newState)
     {
+        //print("ChangeState:" + state + ";" + newState);
         switch (state)
         {
             case CharacterState.Idle:
@@ -588,6 +606,9 @@ public class PlayerController : MoveCharacter
             case CharacterState.Rush:
                 rb.velocity = Vector3.zero;
                 break;
+            case CharacterState.Sprint:
+                rb.velocity = Vector3.zero;
+                break;
             case CharacterState.Die:
                 isDie = false;
                 break;
@@ -644,6 +665,19 @@ public class PlayerController : MoveCharacter
                 aniCollider.Play("Rush", 0, 0);
                 ani.Play("rush_loop", 0, 0);
                 rushTime = totalRushTime;
+                invincibleTime = rushInvincibleTime;
+                if (bodyTrans.localScale.x > 0)
+                {
+                    rb.velocity = Vector3.left * rushSpeed;
+                }
+                else
+                {
+                    rb.velocity = Vector3.right * rushSpeed;
+                }
+                break;
+            case CharacterState.Sprint:
+                aniCollider.Play("Sprint", 0, 0);
+                ani.Play("rush_loop", 0, 0);
                 if (bodyTrans.localScale.x > 0)
                 {
                     rb.velocity = Vector3.left * rushSpeed;
@@ -664,33 +698,28 @@ public class PlayerController : MoveCharacter
         }
     }
 
+    public void CheckTurn()
+    {
+        if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
+        {
+            Turn();
+        }
+        else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
+        {
+            Turn();
+        }
+    }
+
     public void AirMove()
     {
+        CheckTurn();
         if (leftDir.x > 0.3f)
         {
-            //rb.velocity += Vector3.right * airMoveAcc * deltaTime;
-            ////rb.velocity = Vector3.right * maxMoveSpeed;
-            //if (rb.velocity.x > maxMoveSpeed)
-            //{
-                rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-            //}
-            if (bodyTrans.localScale.x > 0)
-            {
-                Turn();
-            }
+            rb.velocity = new Vector3(maxMoveSpeed, rb.velocity.y, rb.velocity.z);
         }
         else if (leftDir.x < -0.3f)
         {
-            //rb.velocity -= Vector3.right * airMoveAcc * deltaTime;
-            ////rb.velocity = Vector3.left * maxMoveSpeed;
-            //if (rb.velocity.x < -maxMoveSpeed)
-            //{
-                rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
-            //}
-            if (bodyTrans.localScale.x < 0)
-            {
-                Turn();
-            }
+            rb.velocity = new Vector3(-maxMoveSpeed, rb.velocity.y, rb.velocity.z);
         }
         else
         {
@@ -757,4 +786,13 @@ public class PlayerController : MoveCharacter
             demonicDic[demonic.id][i].SetSortingOrder(demonic.id * 1000 + i);
         }
     }
+
+    public override void BeHit(int damage, Vector3 force)
+    {
+        if (invincibleTime > 0)
+        {
+            return;
+        }
+        base.BeHit(damage, force);
+    }
 }