Parcourir la source

玩家在空中时也可以召唤使魔,以及相应逻辑迭代,击飞效果问题修复

wulifu il y a 1 an
Parent
commit
e132aae69a

+ 1 - 1
ActionTowerDefense/Assets/Resources/Prefab/Player.prefab

@@ -632,7 +632,7 @@ MonoBehaviour:
   - {fileID: 5440846222648032759, guid: 05825e721b2832f478f66e78daed901f, type: 3}
   - {fileID: 2437299196472462361, guid: a429663f5ce3055459229a7eddc06c58, type: 3}
   demonicSummonPos:
-  - {x: -5, y: 3, z: 0}
+  - {x: -5, y: 0, z: 0}
   - {x: -5, y: 0, z: 0}
   - {x: -5, y: 0, z: 0}
   uiMp: {fileID: 8465211090008398057}

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

@@ -1156,10 +1156,18 @@ PrefabInstance:
   m_Modification:
     m_TransformParent: {fileID: 0}
     m_Modifications:
+    - target: {fileID: 3571941038519084336, guid: 5b538f610930dd743a096c582e2810f4, type: 3}
+      propertyPath: demonicSummonPos.Array.data[0].y
+      value: 0
+      objectReference: {fileID: 0}
     - target: {fileID: 3571941038519084344, guid: 5b538f610930dd743a096c582e2810f4, type: 3}
       propertyPath: m_Name
       value: Player
       objectReference: {fileID: 0}
+    - target: {fileID: 3571941038519084344, guid: 5b538f610930dd743a096c582e2810f4, type: 3}
+      propertyPath: m_IsActive
+      value: 1
+      objectReference: {fileID: 0}
     - target: {fileID: 3571941038519084349, guid: 5b538f610930dd743a096c582e2810f4, type: 3}
       propertyPath: m_RootOrder
       value: 1
@@ -1265,6 +1273,10 @@ PrefabInstance:
       propertyPath: m_Name
       value: EnemyTower
       objectReference: {fileID: 0}
+    - target: {fileID: 3581793008941702770, guid: 9b26b01efd8ba674a98444c19a0af89e, type: 3}
+      propertyPath: m_IsActive
+      value: 1
+      objectReference: {fileID: 0}
     m_RemovedComponents: []
   m_SourcePrefab: {fileID: 100100000, guid: 9b26b01efd8ba674a98444c19a0af89e, type: 3}
 --- !u!1001 &6745549283345970834
@@ -1278,6 +1290,10 @@ PrefabInstance:
       propertyPath: m_Name
       value: Tower
       objectReference: {fileID: 0}
+    - target: {fileID: 6126647545658003341, guid: 27fc9f9c5a91ca44395c454662e9576a, type: 3}
+      propertyPath: m_IsActive
+      value: 1
+      objectReference: {fileID: 0}
     - target: {fileID: 6126647545658003342, guid: 27fc9f9c5a91ca44395c454662e9576a, type: 3}
       propertyPath: m_RootOrder
       value: 7

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

@@ -48,11 +48,6 @@ public class Bullet : MonoBehaviour
 
     public void BeShoot(Character own, Vector3 shootPos, Vector3 dir, int dmg, float fc, bool track = false, Transform target = null)
     {
-        print("BeShoot:" + track + ";" + target);
-        if (target)
-        {
-            print("target:" + target.transform.position.y);
-        }
         startPos = shootPos;
         transform.position = shootPos;
         transform.right = -dir;

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

@@ -327,7 +327,6 @@ public class Demonic : MoveCharacter
                 {
                     rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
                 }
-                rb.velocity = rb.velocity / 5 * 4;
                 break;
             case CharacterState.Attack:
                 if (attackTime <= 0)

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

@@ -268,7 +268,6 @@ public class Enemy : MoveCharacter
                 {
                     rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
                 }
-                rb.velocity = rb.velocity / 5 * 4;
                 break;
             case CharacterState.Attack:
                 if (attackTime <= 0)

+ 83 - 58
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -229,11 +229,6 @@ public class PlayerController : MoveCharacter
         }
     }
 
-    public override void FixedUpdate()
-    {
-        base.FixedUpdate();
-    }
-
     public void Jump()
     {
         SetUpSpeed(jumpSpeed);
@@ -256,6 +251,31 @@ public class PlayerController : MoveCharacter
         //animalAni.SetInteger("state", (int)PlayerState.Rise);
     }
 
+    public bool CheckSummon()
+    {
+        if (cacheSummonTime > 0)
+        {
+            Summon(cacheSummonId);
+            return true;
+        }
+        if (btnWestPress)
+        {
+            Summon(0);
+            return true;
+        }
+        if (btnSouthPress)
+        {
+            Summon(1);
+            return true;
+        }
+        if (btnEastPress)
+        {
+            Summon(2);
+            return true;
+        }
+        return false;
+    }
+
     //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
     public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
     {
@@ -297,35 +317,10 @@ public class PlayerController : MoveCharacter
                     return true;
                 }
             }
-            if (cacheSummonTime > 0)
-            {
-                if (excludeState != CharacterState.Summon)
-                {
-                    Summon(cacheSummonId);
-                    return true;
-                }
-            }
-            if (btnWestPress)
-            {
-                if (excludeState != CharacterState.Summon)
-                {
-                    Summon(0);
-                    return true;
-                }
-            }
-            if (btnSouthPress)
+            if (excludeState != CharacterState.Summon)
             {
-                if (excludeState != CharacterState.Summon)
+                if (CheckSummon())
                 {
-                    Summon(1);
-                    return true;
-                }
-            }
-            if (btnEastPress)
-            {
-                if (excludeState != CharacterState.Summon)
-                {
-                    Summon(2);
                     return true;
                 }
             }
@@ -417,6 +412,8 @@ public class PlayerController : MoveCharacter
         rushTime -= Time.deltaTime;
         cacheRushTime -= Time.deltaTime;
         dieKeepTime -= Time.deltaTime;
+
+        Vector3 velocity = rb.velocity;
         switch (state)
         {
             case CharacterState.Idle:
@@ -424,7 +421,6 @@ public class PlayerController : MoveCharacter
                 {
                     break;
                 }
-                //rb.velocity = Vector3.zero;
                 break;
             case CharacterState.Run:
                 if (CheckPlayerChangeState(CharacterState.Run))
@@ -442,6 +438,10 @@ public class PlayerController : MoveCharacter
                 }
                 break;
             case CharacterState.Rise:
+                if (CheckSummon())
+                {
+                    break;
+                }
                 if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
                 {
                     ChangeState(CharacterState.Rush);
@@ -462,10 +462,13 @@ public class PlayerController : MoveCharacter
                     }
                 }
                 CachedPlayerInput();
-                rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
-                AirMove();
+                rb.velocity = AirMove(rb.velocity);
                 break;
             case CharacterState.Fall:
+                if (CheckSummon())
+                {
+                    break;
+                }
                 if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
                 {
                     ChangeState(CharacterState.Rush);
@@ -505,8 +508,7 @@ public class PlayerController : MoveCharacter
                     }
                 }
                 CachedPlayerInput();
-                rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
-                AirMove();
+                rb.velocity = AirMove(rb.velocity);
                 break;
             case CharacterState.Hurt:
                 if (hurtKeepTime <= 0)
@@ -517,11 +519,6 @@ public class PlayerController : MoveCharacter
                     }
                 }
                 CachedPlayerInput();
-                if (!foot.TrigGround)
-                {
-                    rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
-                }
-                rb.velocity = rb.velocity / 5 * 4;
                 break;
             case CharacterState.Attack:
                 if (attackTime <= 0)
@@ -556,7 +553,6 @@ public class PlayerController : MoveCharacter
                         break;
                     }
                 }
-                Vector3 velocity = rb.velocity;
                 switch (attackState)
                 {
                     case PlayerAttackState.Idle:
@@ -566,12 +562,14 @@ public class PlayerController : MoveCharacter
                             {
                                 SetAttackState(PlayerAttackState.WalkBack);
                                 velocity.x = attackMoveSpeed;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else if (leftDir.x < -0.3f)
                             {
                                 SetAttackState(PlayerAttackState.WalkForward);
                                 velocity.x = -attackMoveSpeed;
+                                rb.velocity = velocity;
                                 break;
                             }
                         }
@@ -581,16 +579,19 @@ public class PlayerController : MoveCharacter
                             {
                                 SetAttackState(PlayerAttackState.WalkForward);
                                 velocity.x = attackMoveSpeed;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else if (leftDir.x < -0.3f)
                             {
                                 SetAttackState(PlayerAttackState.WalkBack);
                                 velocity.x = -attackMoveSpeed;
+                                rb.velocity = velocity;
                                 break;
                             }
                         }
                         velocity.x = 0;
+                        rb.velocity = velocity;
                         break;
                     case PlayerAttackState.WalkForward:
                         if (bodyTrans.localScale.x > 0)
@@ -599,17 +600,20 @@ public class PlayerController : MoveCharacter
                             {
                                 SetAttackState(PlayerAttackState.WalkBack);
                                 velocity.x = attackMoveSpeed;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
                             {
                                 SetAttackState(PlayerAttackState.Idle);
                                 velocity.x = 0;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else
                             {
                                 velocity.x = -attackMoveSpeed;
+                                rb.velocity = velocity;
                             }
                         }
                         else
@@ -618,17 +622,20 @@ public class PlayerController : MoveCharacter
                             {
                                 SetAttackState(PlayerAttackState.WalkBack);
                                 velocity.x = -attackMoveSpeed;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
                             {
                                 SetAttackState(PlayerAttackState.Idle);
                                 velocity.x = 0;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else
                             {
                                 velocity.x = attackMoveSpeed;
+                                rb.velocity = velocity;
                             }
                         }
                         break;
@@ -639,17 +646,20 @@ public class PlayerController : MoveCharacter
                             {
                                 SetAttackState(PlayerAttackState.WalkForward);
                                 velocity.x = -attackMoveSpeed;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
                             {
                                 SetAttackState(PlayerAttackState.Idle);
                                 velocity.x = 0;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else
                             {
                                 velocity.x = attackMoveSpeed;
+                                rb.velocity = velocity;
                             }
                         }
                         else
@@ -658,24 +668,26 @@ public class PlayerController : MoveCharacter
                             {
                                 SetAttackState(PlayerAttackState.WalkForward);
                                 velocity.x = attackMoveSpeed;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
                             {
                                 SetAttackState(PlayerAttackState.Idle);
                                 velocity.x = 0;
+                                rb.velocity = velocity;
                                 break;
                             }
                             else
                             {
                                 velocity.x = -attackMoveSpeed;
+                                rb.velocity = velocity;
                             }
                         }
                         break;
                     default:
                         break;
                 }
-                rb.velocity = velocity;
                 break;
             case CharacterState.Summon:
                 if (summonTime <= 0)
@@ -747,6 +759,18 @@ public class PlayerController : MoveCharacter
             default:
                 break;
         }
+        if (!foot.TrigGround)
+        {
+            if (rb.velocity.y > 0)
+            {
+                rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
+            }
+            else
+            {
+                rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
+            }
+        }
+
         isClickBtnRush = false;
         isKeepBtnRush = false;
         isClickBtnJump = false;
@@ -775,18 +799,17 @@ public class PlayerController : MoveCharacter
 
     public override void ChangeState(CharacterState newState)
     {
-        //print("ChangeState:" + state + ";" + newState);
+        Vector3 velocity = rb.velocity;
         switch (state)
         {
             case CharacterState.Idle:
                 break;
             case CharacterState.Run:
-                rb.velocity = Vector3.zero;
+                velocity.x = 0;
                 break;
             case CharacterState.Rise:
                 break;
             case CharacterState.Fall:
-                rb.velocity = Vector3.zero;
                 break;
             case CharacterState.Hurt:
                 break;
@@ -799,10 +822,10 @@ public class PlayerController : MoveCharacter
             case CharacterState.Summon:
                 break;
             case CharacterState.Rush:
-                rb.velocity = Vector3.zero;
+                velocity = Vector3.zero;
                 break;
             case CharacterState.Sprint:
-                rb.velocity = Vector3.zero;
+                velocity = Vector3.zero;
                 break;
             case CharacterState.Die:
                 isDie = false;
@@ -824,7 +847,7 @@ public class PlayerController : MoveCharacter
                 {
                     ani.Play("idle", 0, 0);
                 }
-                rb.velocity = Vector3.zero;
+                velocity = Vector3.zero;
                 //animalAni.SetInteger("state", (int)PlayerState.Idle);
                 break;
             case CharacterState.Run:
@@ -866,11 +889,11 @@ public class PlayerController : MoveCharacter
                 invincibleTime = rushInvincibleTime;
                 if (bodyTrans.localScale.x > 0)
                 {
-                    rb.velocity = Vector3.left * rushSpeed;
+                    velocity = Vector3.left * rushSpeed;
                 }
                 else
                 {
-                    rb.velocity = Vector3.right * rushSpeed;
+                    velocity = Vector3.right * rushSpeed;
                 }
                 mp -= rushCostMp;
                 uiMp.Show(mp, totalMp);
@@ -880,11 +903,11 @@ public class PlayerController : MoveCharacter
                 ani.Play("rush_loop", 0, 0);
                 if (bodyTrans.localScale.x > 0)
                 {
-                    rb.velocity = Vector3.left * rushSpeed;
+                    velocity = Vector3.left * rushSpeed;
                 }
                 else
                 {
-                    rb.velocity = Vector3.right * rushSpeed;
+                    velocity = Vector3.right * rushSpeed;
                 }
                 break;
             case CharacterState.Die:
@@ -896,6 +919,7 @@ public class PlayerController : MoveCharacter
             default:
                 break;
         }
+        rb.velocity = velocity;
     }
 
     public void CheckTurn()
@@ -910,21 +934,22 @@ public class PlayerController : MoveCharacter
         }
     }
 
-    public void AirMove()
+    public Vector3 AirMove(Vector3 velocity)
     {
         CheckTurn();
         if (leftDir.x > 0.3f)
         {
-            rb.velocity = new Vector3(moveSpeed, rb.velocity.y, rb.velocity.z);
+            velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
         }
         else if (leftDir.x < -0.3f)
         {
-            rb.velocity = new Vector3(-moveSpeed, rb.velocity.y, rb.velocity.z);
+            velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
         }
         else
         {
-            rb.velocity = new Vector3(0, rb.velocity.y, rb.velocity.z);
+            velocity = new Vector3(0, velocity.y, velocity.z);
         }
+        return velocity;
     }
 
     public void Summon(int id)