diff --git a/Role/Bullet.cs b/Role/Bullet.cs index 748b30c..4f7e89f 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -97,14 +97,20 @@ public class Bullet : MonoBehaviour private void OnTriggerEnter2D(Collider2D collision) { - Debug.Log("进入检测范围"); + //Debug.Log("进入检测范围"); Role Crole = collision.gameObject.GetComponent(); if(Crole) { if(Crole.camp!= role.camp) { Debug.Log(this.role.gameObject.name+"进行攻击计算"); - Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role }); + int direction=0; + if (collision.transform.position.x>=transform.position.x)//子弹打到敌人左边,飘字显示到右边 + { + direction = 1; + } + + Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role },direction); attackObj.bulltes.Remove(this.gameObject); if (myBulletType!=BulletType.Spraying) @@ -112,10 +118,41 @@ public class Bullet : MonoBehaviour attackObj.bulltes.Remove(this.gameObject); //Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count); Destroy(this.gameObject); - } + } } } } + private float lastDamageTime = 0f; + private void OnTriggerStay2D(Collider2D collision) + { + Role Crole = collision.gameObject.GetComponent(); + if (Crole) + { + if (Crole.camp != role.camp) + { + + + int direction = 0; + if (collision.transform.position.x >= transform.position.x)//子弹打到敌人左边,飘字显示到右边 + { + direction = 1; + } + + if (myBulletType == BulletType.Spraying) + { + + if (Time.time - lastDamageTime > 1f) // 每秒扣一次血 + { + Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role }); + lastDamageTime = Time.time; + } + + + } + } + } + } + private void OnTriggerExit2D(Collider2D collision) { diff --git a/Role/Fun.cs b/Role/Fun.cs index f7837f8..0eca5d1 100644 --- a/Role/Fun.cs +++ b/Role/Fun.cs @@ -48,16 +48,16 @@ public class Fun : Base /// - /// 扣血 传入参数 目标,伤害值,攻击类型,使用者 + /// 扣血 传入参数 目标,伤害值,攻击类型,使用者,子弹射来的方向(0是右边,1是左边) /// /// - public void bloodLoss(object[] objects)//目标,伤害值,攻击类型,使用者 + public void bloodLoss(object[] objects,int direction=1)//目标,伤害值,攻击类型,使用者,子弹射来的方向 { Role targetAudience = (Role)objects[0]; float harm = (float)objects[1]; DamageType damageType = (DamageType)objects[2]; Role UserObj = (Role)objects[3]; - + float finalDamage = harm; switch (damageType) @@ -79,6 +79,7 @@ public class Fun : Base } targetAudience.Hp -= finalDamage; + targetAudience.HurtDirectin = direction; } diff --git a/Role/Role.cs b/Role/Role.cs index 5ae5354..f7ec191 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -46,6 +46,7 @@ public class Role : Fun [Header("自己的画布")]public Canvas _Canvas; [Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件 + [Header("被打的方向")] public int HurtDirectin; public float Hp { @@ -69,6 +70,8 @@ public class Role : Fun if (HpTextPrefab != null && hp < maxHp) { GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform); + go.GetComponent().direction = HurtDirectin; + go.GetComponent().CreateText(); go.GetComponent().text = (temp - hp).ToString(); // 显示伤害值 FlashRedEffect(); // 血量减少时的红色闪烁效果 StopDoTween(0.2f); // 停止任何进行中的 DoTween 动画,0.2s为示例值