LAPTOP-OM1V99U2\永远de小亡灵 1 rok pred
rodič
commit
78f5fba4bb

+ 64 - 13
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -110,6 +110,9 @@ public class PlayerController : MoveCharacter
 
     public Vector2 moveVec;         //玩家不动时移动数据
 
+    public float reviveTime;        //复活时间
+    public float totalReviveTime;
+
     public bool isBaseBtnOut = false;
 
 
@@ -1196,21 +1199,19 @@ public class PlayerController : MoveCharacter
             case CharacterState.Die:
                 if (dieKeepTime <= 0)
                 {
-                    switch (playerId)
+
+                    if (isRevive)
                     {
-                        case 0:
-                            SpiritSystem.isP1In = true;
-                            SpiritSystem.isP1Out = false;
-                            break;
-                        case 1:
-                            SpiritSystem.isP2In = true;
-                            SpiritSystem.isP2Out = false;
-                            break;
-                        default:
-                            break;
+                        reviveTime += Time.deltaTime;
+                        if(reviveTime >= totalReviveTime)
+                        {
+                            PlayerRevive();
+                        }
+                    }
+                    else
+                    {
+                        PlayerDie();
                     }
-                    gameObject.SetActive(false);
-                    break;
                 }
                 break;
             case CharacterState.Weak:
@@ -1294,6 +1295,52 @@ public class PlayerController : MoveCharacter
         }
         uiMp.Show(mp, totalMp);
     }
+    public void PlayerDie()
+    {
+        switch (playerId)
+        {
+            case 0:
+                SpiritSystem.isP1In = true;
+                SpiritSystem.isP1Out = false;
+                break;
+            case 1:
+                SpiritSystem.isP2In = true;
+                SpiritSystem.isP2Out = false;
+                break;
+            default:
+                break;
+        }
+        bodyTrans.gameObject.SetActive(false);
+        uiHp.transform.parent.gameObject.SetActive(false);
+        rb.constraints = RigidbodyConstraints.FreezeAll;
+        isRevive = true;
+        reviveTime = 0;
+    }
+    public void PlayerRevive()
+    {
+        bodyTrans.gameObject.SetActive(true);
+        uiHp.transform.parent.gameObject.SetActive(true);
+        rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
+        transform.position = new Vector3(142 + 4 * playerId, 0, 0);
+        switch (playerId)
+        {
+            case 0:
+                SpiritSystem.isP1In = false;
+                SpiritSystem.isP1Out = true;
+                SpiritSystem.player1 = gameObject;
+                SpiritSystem.p1Spirits = GetComponent<Spirits>();
+                break;
+            case 1:
+                SpiritSystem.isP2In = false;
+                SpiritSystem.isP2Out = true;
+                SpiritSystem.player2 = gameObject;
+                SpiritSystem.p2Spirits = GetComponent<Spirits>();
+                break;
+            default:
+                break;
+        }
+        Init();
+    }
 
     public bool isMpRepel = true;
 
@@ -1326,6 +1373,10 @@ public class PlayerController : MoveCharacter
                 velocity.x = 0;
                 break;
             case CharacterState.Rise:
+                if (!canFly)
+                {
+                    bodyCollider.SetActive(true);
+                }
                 break;
             case CharacterState.Fall:
                 break;