Explorar el Código

敌方法师除了不能对玩家作用,都ok了

SZAND\msx_2 hace 1 año
padre
commit
a31d1b9f52

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

@@ -895,6 +895,9 @@ MonoBehaviour:
   attackState: 0
   attackMoveSpeed: 5
   rushDir: {x: 0, y: 0, z: 0}
+  lostMp: 0
+  soul: {fileID: 1723151111827507807, guid: e2b65aa482f2f1447a4074208d72b778, type: 3}
+  soulCollector: {fileID: 3739918129319493242}
   isClickBtnJump: 0
   isClickBtnRush: 0
   isKeepBtnRush: 0

+ 13 - 1
ActionTowerDefense/Assets/Scripts/MoveCharacter.cs

@@ -39,8 +39,10 @@ public class MoveCharacter : Character
     private float curHeight;    //当前所在高度
     private float rotateSpeed;  //旋转速度
     private float rotateDir;    //旋转方向
+    private float backSpeed;    //往后退的速度
 
     private Vector3 origPos;     //初始位置
+    private float pastTime;     //上升已用时间
     private float rise = 1;
     private float down = -1;
     private Vector3 oneClockwise = new Vector3(0, 0, 1);
@@ -85,6 +87,11 @@ public class MoveCharacter : Character
         ChangeState(CharacterState.Rise);
         floatState = 1;
         riseTime = Random.Range(minTime, maxTime);
+        backSpeed = Random.Range(1, 4);
+        if (gameObject.tag == "Enemy" || gameObject.tag == "Player")
+        {
+            backSpeed = -backSpeed;
+        }
         origPos = transform.position;
         curHeight = origPos.y;
         curTime = 0;
@@ -116,6 +123,7 @@ public class MoveCharacter : Character
             if (curHeight >= height - 0.02f)
             {
                 floatState = 2;
+                pastTime = curTime;
                 ChangeState(CharacterState.Float);
                 transform.position = new Vector3(origPos.x, height, origPos.z);
             }
@@ -124,7 +132,7 @@ public class MoveCharacter : Character
         {
             RotateSelf();
             curTime += Time.deltaTime;
-            transform.position = new Vector3(origPos.x, height, origPos.z);
+            transform.position = new Vector3(origPos.x + backSpeed * (curTime - pastTime), height, origPos.z);
             if (curTime >= floatTime)
             {
                 floatState = 3;
@@ -155,6 +163,10 @@ public class MoveCharacter : Character
                 {
                     transform.localEulerAngles = new Vector3(0, 0, 0);
                     floatState = 0;
+                    if (gameObject.tag == "Player")
+                    {
+                        GetComponent<PlayerController>().soulCollector.enabled = true;
+                    }
                 }
             }
         }

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

@@ -93,6 +93,11 @@ public class PlayerController : MoveCharacter
     private int currentSpirit;  //当前将要召唤的英灵种类
     private Spirits spirits;
 
+    public float lostMp;
+
+    public GameObject soul;
+    private float addMp = 10;
+    public Collider soulCollector;
 
     public bool btnJumpPress
     {
@@ -1011,13 +1016,33 @@ public class PlayerController : MoveCharacter
         SearchTarget();
         attackTarget = targetCharacter;
 
-        if (mp < totalMp)
+        if (state != CharacterState.Float)
         {
-            mp += mpReplySpeed * Time.deltaTime;
+            if (mp < totalMp)
+            {
+                mp += mpReplySpeed * Time.deltaTime;
+            }
+            if (mp > totalMp)
+            {
+                mp = totalMp;
+            }
         }
-        if (mp > totalMp)
+        else
         {
-            mp = totalMp;
+            if (mp > 0)
+            {
+                mp -= mpReplySpeed * Time.deltaTime;
+                lostMp += mpReplySpeed * Time.deltaTime;
+            }
+            if (mp < 0)
+            {
+                mp = 0;
+            }
+            if (lostMp >= addMp)
+            {
+                Instantiate(soul, transform.position, new Quaternion(0, 0, 0, 0), null);
+                lostMp = 0;
+            }
         }
         uiMp.Show(mp, totalMp);
     }

+ 5 - 1
ActionTowerDefense/Assets/Scripts/Spirits/FloatEffect.cs

@@ -34,7 +34,11 @@ public class FloatEffect : MonoBehaviour
         }
         else if(isEnemy && other.gameObject.layer == 6)
         {
-
+            GameObject ga = other.transform.parent.parent.parent.gameObject;
+            print(1);
+            ga.GetComponent<PlayerController>().lostMp = 0;
+            ga.GetComponent<PlayerController>().soulCollector.enabled = false;
+            ga.GetComponent<PlayerController>().FloatStateOn();
         }
     }