Explorar o código

"(UI表现:血条下面加一个蓝色条即可)
1.召唤不同的怪物会消耗不同的魔法值,当魔法值不足时,无法召唤。
2.dash:按一次消耗X。按住dash不放会一直消耗魔法值
3.魔法值会缓慢恢复。
4. "

wulifu hai 1 ano
pai
achega
dafee5cc9a

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

@@ -114,7 +114,7 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
-  m_AnchoredPosition: {x: 0, y: 150}
+  m_AnchoredPosition: {x: 0, y: 200}
   m_SizeDelta: {x: 150, y: 30}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!222 &205997966
@@ -215,6 +215,7 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children:
   - {fileID: 205997963}
+  - {fileID: 5024842401036440121}
   m_Father: {fileID: 3571941038519084349}
   m_RootOrder: 1
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -493,6 +494,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   mecanim: {fileID: 6843453365888964567}
+  meshRenderer: {fileID: 0}
   ani: {fileID: 6197716555580445942}
   aniCollider: {fileID: 5072770566235913242}
   rb: {fileID: 3571941038519084339}
@@ -515,10 +517,14 @@ MonoBehaviour:
   attackType: 0
   bulletPrefab: {fileID: 0}
   shootPos: []
+  dieKeepTime: 0
+  totalDieKeepTime: 2
+  attackTarget: {fileID: 0}
+  shootTrack: 0
   foot: {fileID: 3571941039716665623}
   extraRiseGravity: -28.8
   extraFallGravity: -14.4
-  maxMoveSpeed: 14.4
+  moveSpeed: 20
   hurtKeepTime: 0
   totalHurtKeepTime: 0.5
   demonicPrefabs:
@@ -529,11 +535,18 @@ MonoBehaviour:
   - {x: -5, y: 0, z: 0}
   - {x: -5, y: 0, z: 0}
   - {x: -5, y: 0, z: 0}
+  uiMp: {fileID: 8465211090008398057}
   jumpSpeed: 20
   airJumpSpeed: 15
   rushSpeed: 54
+  mp: 0
+  totalMp: 100
+  mpReplySpeed: 1
+  rushCostMp: 5
+  sprintCostMp: 5
   invincibleTime: 0
   totalInvincibleTime: 2
+  rushInvincibleTime: 0.2
   canJumpTime: 0
   leaveGroundCanJumpTime: 0.15
   cacheJumpTime: 0
@@ -552,6 +565,7 @@ MonoBehaviour:
   airJumped: 0
   isClickBtnJump: 0
   isClickBtnRush: 0
+  isKeepBtnRush: 0
   isClickBtnSouth: 0
   isClickBtnEast: 0
   isClickBtnWest: 0
@@ -631,6 +645,82 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   trigGroundList: []
+--- !u!1 &4574901846507359337
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 3837148009549577497}
+  - component: {fileID: 1036923190297103172}
+  - component: {fileID: 7367632414814067470}
+  m_Layer: 6
+  m_Name: Progress
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!224 &3837148009549577497
+RectTransform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 4574901846507359337}
+  m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 5024842401036440121}
+  m_RootOrder: 0
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+  m_AnchorMin: {x: 0.5, y: 0.5}
+  m_AnchorMax: {x: 0.5, y: 0.5}
+  m_AnchoredPosition: {x: 0, y: 0}
+  m_SizeDelta: {x: 150, y: 30}
+  m_Pivot: {x: 0.5, y: 0.5}
+--- !u!222 &1036923190297103172
+CanvasRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 4574901846507359337}
+  m_CullTransparentMesh: 1
+--- !u!114 &7367632414814067470
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 4574901846507359337}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Material: {fileID: 0}
+  m_Color: {r: 0, g: 0.65848875, b: 1, a: 1}
+  m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
+  m_Maskable: 1
+  m_OnCullStateChanged:
+    m_PersistentCalls:
+      m_Calls: []
+  m_Sprite: {fileID: 21300000, guid: 97bdb0b0817469147954ce720ea6f795, type: 3}
+  m_Type: 3
+  m_PreserveAspect: 0
+  m_FillCenter: 1
+  m_FillMethod: 0
+  m_FillAmount: 1
+  m_FillClockwise: 1
+  m_FillOrigin: 0
+  m_UseSpriteMesh: 0
+  m_PixelsPerUnitMultiplier: 1
 --- !u!1 &5553794633741559699
 GameObject:
   m_ObjectHideFlags: 0
@@ -713,7 +803,7 @@ MeshRenderer:
   m_AutoUVMaxAngle: 89
   m_LightmapParameters: {fileID: 0}
   m_SortingLayerID: -1730265859
-  m_SortingLayer: 1
+  m_SortingLayer: 5
   m_SortingOrder: 0
   m_AdditionalVertexStreams: {fileID: 0}
 --- !u!95 &6197716555580445942
@@ -869,6 +959,113 @@ Transform:
   m_Father: {fileID: 3571941038519084349}
   m_RootOrder: 0
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1 &5778848979504649158
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 5024842401036440121}
+  - component: {fileID: 4227556088956400045}
+  - component: {fileID: 6734461913227052064}
+  - component: {fileID: 855278447848915896}
+  - component: {fileID: 8465211090008398057}
+  m_Layer: 6
+  m_Name: MP
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!224 &5024842401036440121
+RectTransform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5778848979504649158}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children:
+  - {fileID: 3837148009549577497}
+  m_Father: {fileID: 1969773273}
+  m_RootOrder: 1
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+  m_AnchorMin: {x: 0.5, y: 0.5}
+  m_AnchorMax: {x: 0.5, y: 0.5}
+  m_AnchoredPosition: {x: 0, y: 160}
+  m_SizeDelta: {x: 150, y: 30}
+  m_Pivot: {x: 0.5, y: 0.5}
+--- !u!222 &4227556088956400045
+CanvasRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5778848979504649158}
+  m_CullTransparentMesh: 1
+--- !u!114 &6734461913227052064
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5778848979504649158}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Material: {fileID: 0}
+  m_Color: {r: 0, g: 0.01957494, b: 0.32941177, a: 1}
+  m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
+  m_Maskable: 1
+  m_OnCullStateChanged:
+    m_PersistentCalls:
+      m_Calls: []
+  m_Sprite: {fileID: 21300000, guid: 97bdb0b0817469147954ce720ea6f795, type: 3}
+  m_Type: 0
+  m_PreserveAspect: 0
+  m_FillCenter: 1
+  m_FillMethod: 4
+  m_FillAmount: 1
+  m_FillClockwise: 1
+  m_FillOrigin: 0
+  m_UseSpriteMesh: 0
+  m_PixelsPerUnitMultiplier: 1
+--- !u!114 &855278447848915896
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5778848979504649158}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: e19747de3f5aca642ab2be37e372fb86, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_EffectColor: {r: 0, g: 0, b: 0, a: 1}
+  m_EffectDistance: {x: 3, y: -3}
+  m_UseGraphicAlpha: 1
+--- !u!114 &8465211090008398057
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5778848979504649158}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: c5cfe48b68a3fd64f95e7a1c19316726, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  imgHp: {fileID: 7367632414814067470}
 --- !u!1 &8722136878745494474
 GameObject:
   m_ObjectHideFlags: 0

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

@@ -78,7 +78,7 @@ public class Character : MonoBehaviour
         }
 
         hp = totalHp;
-        uiHp.ShowHP(hp, totalHp);
+        uiHp.Show(hp, totalHp);
         ChangeState(CharacterState.Idle);
     }
 
@@ -105,7 +105,7 @@ public class Character : MonoBehaviour
     public virtual void BeHit(int damage, Vector3 force)
     {
         hp -= damage;
-        uiHp.ShowHP(hp, totalHp);
+        uiHp.Show(hp, totalHp);
         rb.AddForce(force);
         if (hp < 0)
         {

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

@@ -7,6 +7,7 @@ using UnityEngine;
 public class Demonic : MoveCharacter
 {
     public int id;
+    public float costMp = 10;
     public SearchTrigger searchTrigger;
     public SearchState searchState;
     public List<TargetType> targetTypes;

+ 1 - 1
ActionTowerDefense/Assets/Scripts/EnemyTower.cs

@@ -115,7 +115,7 @@ public class EnemyTower : Character
     public override void BeHit(int damage, Vector3 force)
     {
         hp -= damage;
-        uiHp.ShowHP(hp, totalHp);
+        uiHp.Show(hp, totalHp);
         if (hp < 0)
         {
             ChangeState(CharacterState.Die);

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

@@ -27,12 +27,18 @@ public class PlayerController : MoveCharacter
     public List<GameObject> demonicPrefabs;
     public List<Vector3> demonicSummonPos;
     public Dictionary<int, List<Demonic>> demonicDic;
+    public UIHP uiMp;
 
     public float jumpSpeed = 10;
     public float airJumpSpeed = 10;
     //public float moveAcc = 5f;
     //public float airMoveAcc = 3f;
     public float rushSpeed = 100;
+    public float mp;
+    public float totalMp;
+    public float mpReplySpeed = 1;
+    public float rushCostMp = 5;
+    public float sprintCostMp = 5;
 
     [HideInInspector]
     public float invincibleTime;
@@ -154,6 +160,13 @@ public class PlayerController : MoveCharacter
         }
     }
 
+    public override void Init()
+    {
+        base.Init();
+        mp = totalMp;
+        uiMp.Show(mp, totalMp);
+    }
+
     private void Awake()
     {
         if (!instance)
@@ -233,7 +246,7 @@ public class PlayerController : MoveCharacter
     {
         if (!foot.TrigGround)
         {
-            if (btnRushPress || cacheRushTime > 0)
+            if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
             {
                 if (excludeState != CharacterState.Rush)
                 {
@@ -274,7 +287,6 @@ public class PlayerController : MoveCharacter
                 if (excludeState != CharacterState.Summon)
                 {
                     Summon(cacheSummonId);
-                    ChangeState(CharacterState.Summon);
                     return true;
                 }
             }
@@ -283,7 +295,6 @@ public class PlayerController : MoveCharacter
                 if (excludeState != CharacterState.Summon)
                 {
                     Summon(0);
-                    ChangeState(CharacterState.Summon);
                     return true;
                 }
             }
@@ -292,7 +303,6 @@ public class PlayerController : MoveCharacter
                 if (excludeState != CharacterState.Summon)
                 {
                     Summon(1);
-                    ChangeState(CharacterState.Summon);
                     return true;
                 }
             }
@@ -301,11 +311,10 @@ public class PlayerController : MoveCharacter
                 if (excludeState != CharacterState.Summon)
                 {
                     Summon(2);
-                    ChangeState(CharacterState.Summon);
                     return true;
                 }
             }
-            if (btnRushPress || cacheRushTime > 0)
+            if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
             {
                 if (excludeState != CharacterState.Rush)
                 {
@@ -419,7 +428,7 @@ public class PlayerController : MoveCharacter
                 }
                 break;
             case CharacterState.Rise:
-                if (btnRushPress || cacheRushTime > 0)
+                if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
                 {
                     ChangeState(CharacterState.Rush);
                     break;
@@ -443,7 +452,7 @@ public class PlayerController : MoveCharacter
                 AirMove();
                 break;
             case CharacterState.Fall:
-                if (btnRushPress || cacheRushTime > 0)
+                if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
                 {
                     ChangeState(CharacterState.Rush);
                     break;
@@ -551,6 +560,15 @@ public class PlayerController : MoveCharacter
                         break;
                     }
                 }
+                if (mp < sprintCostMp * Time.deltaTime)
+                {
+                    if (CheckPlayerChangeState(CharacterState.Rush))
+                    {
+                        break;
+                    }
+                }
+                mp -= sprintCostMp * Time.deltaTime;
+                uiMp.Show(mp, totalMp);
                 CachedPlayerInput();
                 CheckTurn();
                 if (bodyTrans.localScale.x > 0)
@@ -579,6 +597,16 @@ public class PlayerController : MoveCharacter
         isClickBtnEast = false;
         isClickBtnNorth = false;
         isClickBtnWest = false;
+
+        if (mp < totalMp)
+        {
+            mp += mpReplySpeed * Time.deltaTime;
+        }
+        if (mp > totalMp)
+        {
+            mp = totalMp;
+        }
+        uiMp.Show(mp, totalMp);
     }
 
     public override void ChangeState(CharacterState newState)
@@ -674,6 +702,8 @@ public class PlayerController : MoveCharacter
                 {
                     rb.velocity = Vector3.right * rushSpeed;
                 }
+                mp -= rushCostMp;
+                uiMp.Show(mp, totalMp);
                 break;
             case CharacterState.Sprint:
                 aniCollider.Play("Sprint", 0, 0);
@@ -740,6 +770,14 @@ public class PlayerController : MoveCharacter
             return;
         }
         GameObject prefab = demonicPrefabs[id];
+        if (!CheckCanSummon(id))
+        {
+            return;
+        }
+        ChangeState(CharacterState.Summon);
+        float costMp = prefab.GetComponent<Demonic>().costMp;
+        mp -= costMp;
+        uiMp.Show(mp, totalMp);
         GameObject demonicObj = PoolManager.Instantiate(prefab);
         Demonic demonic = demonicObj.GetComponent<Demonic>();
         demonic.id = id;
@@ -795,4 +833,16 @@ public class PlayerController : MoveCharacter
         }
         base.BeHit(damage, force);
     }
+
+    public bool CheckCanSummon(int id)
+    {
+        GameObject prefab = demonicPrefabs[id];
+        float costMp = prefab.GetComponent<Demonic>().costMp;
+        if (mp < costMp)
+        {
+            Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
+            return false;
+        }
+        return true;
+    }
 }

+ 1 - 1
ActionTowerDefense/Assets/Scripts/Tower.cs

@@ -116,7 +116,7 @@ public class Tower : Character
     public override void BeHit(int damage, Vector3 force)
     {
         hp -= damage;
-        uiHp.ShowHP(hp, totalHp);
+        uiHp.Show(hp, totalHp);
         if (hp < 0)
         {
             ChangeState(CharacterState.Die);

+ 6 - 1
ActionTowerDefense/Assets/Scripts/UIHP.cs

@@ -6,8 +6,13 @@ using UnityEngine.UI;
 public class UIHP : MonoBehaviour
 {
     public Image imgHp;
-    public void ShowHP(int hp, int totalHp)
+    public void Show(int hp, int totalHp)
     {
         imgHp.fillAmount = (float)hp / (float)totalHp;
     }
+
+    public void Show(float hp, float totalHp)
+    {
+        imgHp.fillAmount = hp / totalHp;
+    }
 }