Browse Source

起手式打到防御塔,防御塔跳字是白色

WGL 1 month ago
parent
commit
27bf312cfb

+ 52 - 0
ActionTowerDefense/Assets/Scripts/Characters/Character.cs

@@ -275,6 +275,58 @@ public class Character : MonoBehaviour
     //造成伤害附加其他效果
     public virtual void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom, int damage = -1)
     {
+        if (invincibleTime > 0)
+        {
+            return;
+        }
+        AttackInfo attackInfo = attackMethod.attackInfo;
+
+        int damageData;
+        if (damage == -1)
+        {
+            damageData = attackInfo.damage;
+        }
+        else
+        {
+            damageData = damage;
+        }
+        hp -= damageData;
+
+        //伤害跳字
+        if (showInjuryNum)
+        {
+            GameObject injuryNum;
+            //是起手式
+            if ((attackFrom.CompareTag("Demonic") || attackFrom.CompareTag("Player")) && attackInfo.attackMethod_Type == AttackMethod_Type.Attack_Summon)
+            {
+                injuryNum = PoolManager.Instantiate(injuryNumTextSummon);
+                injuryNum.transform.position = new Vector3(
+                    transform.position.x + injuryNumPos_summon.x + Random.Range(-injuryNumRandom_summon.x / 2f, injuryNumRandom_summon.x / 2f),
+                    transform.position.y + injuryNumPos_summon.y + Random.Range(-injuryNumRandom_summon.y / 2f, injuryNumRandom_summon.y / 2f),
+                    transform.position.z);
+            }
+            //不是起手式
+            else
+            {
+                injuryNum = PoolManager.Instantiate(injuryNumText);
+                injuryNum.transform.position = new Vector3(
+                    transform.position.x + injuryNumPos_march.x + Random.Range(-injuryNumRandom_march.x / 2f, injuryNumRandom_march.x / 2f),
+                    transform.position.y + injuryNumPos_march.y + Random.Range(-injuryNumRandom_march.y / 2f, injuryNumRandom_march.y / 2f),
+                    transform.position.z);
+            }
+
+            TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
+            text.text = damageData.ToString();
+        }
+        if (uiHp)
+        {
+            uiHp.Show(hp, totalHp);
+        }
+        if (hp <= 0)
+        {
+            ChangeState(CharacterState.Die);
+            return;
+        }
     }
 
     public virtual Vector3 GetMoveDir()

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

@@ -129,6 +129,6 @@ public class EnemyTower : Character
 
     public override void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom, int damage = -1)
     {
-        base.BeHit(attackMethod.attackInfo.damage);
+        base.BeHit(attackMethod,attackFrom,damage);
     }
 }