فهرست منبع

变身时长按变身键2s解除变身

SZAND\msx_2 1 سال پیش
والد
کامیت
ce52f5f9fc

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

@@ -950,6 +950,7 @@ MonoBehaviour:
   isinputK: 0
   isinputL: 0
   moveVec: {x: 0, y: 0}
+  relieveTranTime: 2
   isClickBtnJump: 0
   isClickBtnRush: 0
   isKeepBtnRush: 0

+ 67 - 4
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -111,6 +111,10 @@ public class PlayerController : MoveCharacter
 
     public Vector2 moveVec;         //玩家不动时移动数据
 
+    public float relieveTranTime;   //解除变身所需长按时间
+    private bool isTryingToRelieve = false;
+    private float pressTime;
+
     public bool btnJumpPress
     {
         get
@@ -351,6 +355,16 @@ public class PlayerController : MoveCharacter
         if (isTransfiguration)
         {
             bodyTrans.position = spiritObj.transform.position;
+            if (isTryingToRelieve)
+            {
+                pressTime += Time.deltaTime;
+                if (pressTime >= relieveTranTime)
+                {
+                    EndTransfiguration(endChange);
+                    isTryingToRelieve = false;
+                    pressTime = 0;
+                }
+            }
         }
     }
 
@@ -446,23 +460,71 @@ public class PlayerController : MoveCharacter
     }
     void OnSummonSpirit()
     {
-        if (!isFloat && canMove)
+        if (!isTransfiguration && !isFloat && canMove)
             isSpiritSummon = true;
+        if(isTransfiguration && currentSpirit == 0)
+        {
+            isTryingToRelieve = true;
+        }
+    }
+    void OnSummonSpiritUp()
+    {
+        if (isTryingToRelieve && currentSpirit == 0)
+        {
+            isTryingToRelieve = false;
+            pressTime = 0;
+        }
     }
     void OnSummonSpirit1()
     {
-        if (!isFloat && canMove)
+        if (!isTransfiguration && !isFloat && canMove)
             isSpiritSummon1 = true;
+        if (isTransfiguration && currentSpirit == 1)
+        {
+            isTryingToRelieve = true;
+        }
+    }
+    void OnSummonSpirit1Up()
+    {
+        if (isTryingToRelieve && currentSpirit == 1)
+        {
+            isTryingToRelieve = false;
+            pressTime = 0;
+        }
     }
     void OnSummonSpirit2()
     {
-        if (!isFloat && canMove)
+        if (!isTransfiguration && !isFloat && canMove)
             isSpiritSummon2 = true;
+        if (isTransfiguration && currentSpirit == 2)
+        {
+            isTryingToRelieve = true;
+        }
+    }
+    void OnSummonSpirit2Up()
+    {
+        if (isTryingToRelieve && currentSpirit == 2)
+        {
+            isTryingToRelieve = false;
+            pressTime = 0;
+        }
     }
     void OnSummonSpirit3()
     {
-        if (!isFloat && canMove)
+        if (!isTransfiguration && !isFloat && canMove)
             isSpiritSummon3 = true;
+        if (isTransfiguration && currentSpirit == 3)
+        {
+            isTryingToRelieve = true;
+        }
+    }
+    void OnSummonSpirit3Up()
+    {
+        if (isTryingToRelieve && currentSpirit == 3)
+        {
+            isTryingToRelieve = false;
+            pressTime = 0;
+        }
     }
     public void Jump()
     {
@@ -1403,6 +1465,7 @@ public class PlayerController : MoveCharacter
     {
         playerSoulCollector = soulCollector;
         id = id - 3;
+        currentSpirit = id;
         if (id >= changePrefabs.Count)
         {
             Debug.LogError("未配置" + id + "号变身");