飘字修改

This commit is contained in:
GL 2024-12-18 20:43:54 +08:00
parent 84ca89c647
commit 8fde270423
3 changed files with 47 additions and 6 deletions

View File

@ -97,14 +97,20 @@ public class Bullet : MonoBehaviour
private void OnTriggerEnter2D(Collider2D collision) private void OnTriggerEnter2D(Collider2D collision)
{ {
Debug.Log("½øÈë¼ì²â·¶Î§"); //Debug.Log("进入检测范围");
Role Crole = collision.gameObject.GetComponent<Role>(); Role Crole = collision.gameObject.GetComponent<Role>();
if(Crole) if(Crole)
{ {
if(Crole.camp!= role.camp) if(Crole.camp!= role.camp)
{ {
Debug.Log(this.role.gameObject.name+"进行攻击计算"); 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); attackObj.bulltes.Remove(this.gameObject);
if (myBulletType!=BulletType.Spraying) if (myBulletType!=BulletType.Spraying)
@ -112,10 +118,41 @@ public class Bullet : MonoBehaviour
attackObj.bulltes.Remove(this.gameObject); attackObj.bulltes.Remove(this.gameObject);
//Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count); //Debug.Log("对象已成功移除。当前列表数量:" + attackObj.bulltes.Count);
Destroy(this.gameObject); Destroy(this.gameObject);
} }
} }
} }
} }
private float lastDamageTime = 0f;
private void OnTriggerStay2D(Collider2D collision)
{
Role Crole = collision.gameObject.GetComponent<Role>();
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) private void OnTriggerExit2D(Collider2D collision)
{ {

View File

@ -48,16 +48,16 @@ public class Fun : Base
/// <summary> /// <summary>
/// 扣血 传入参数 目标,伤害值,攻击类型,使用者 /// 扣血 传入参数 目标,伤害值,攻击类型,使用者子弹射来的方向0是右边1是左边
/// </summary> /// </summary>
/// <param name="objects"></param> /// <param name="objects"></param>
public void bloodLoss(object[] objects)//目标,伤害值,攻击类型,使用者 public void bloodLoss(object[] objects,int direction=1)//目标,伤害值,攻击类型,使用者,子弹射来的方向
{ {
Role targetAudience = (Role)objects[0]; Role targetAudience = (Role)objects[0];
float harm = (float)objects[1]; float harm = (float)objects[1];
DamageType damageType = (DamageType)objects[2]; DamageType damageType = (DamageType)objects[2];
Role UserObj = (Role)objects[3]; Role UserObj = (Role)objects[3];
float finalDamage = harm; float finalDamage = harm;
switch (damageType) switch (damageType)
@ -79,6 +79,7 @@ public class Fun : Base
} }
targetAudience.Hp -= finalDamage; targetAudience.Hp -= finalDamage;
targetAudience.HurtDirectin = direction;
} }

View File

@ -46,6 +46,7 @@ public class Role : Fun
[Header("自己的画布")]public Canvas _Canvas; [Header("自己的画布")]public Canvas _Canvas;
[Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件 [Header("自己的图片")] public SpriteRenderer spriteRenderers; // 存储所有的SpriteRenderer组件
[Header("被打的方向")] public int HurtDirectin;
public float Hp public float Hp
{ {
@ -69,6 +70,8 @@ public class Role : Fun
if (HpTextPrefab != null && hp < maxHp) if (HpTextPrefab != null && hp < maxHp)
{ {
GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform); GameObject go = GameObject.Instantiate(HpTextPrefab, _Canvas.transform);
go.GetComponent<SnowHpControl>().direction = HurtDirectin;
go.GetComponent<SnowHpControl>().CreateText();
go.GetComponent<Text>().text = (temp - hp).ToString(); // 显示伤害值 go.GetComponent<Text>().text = (temp - hp).ToString(); // 显示伤害值
FlashRedEffect(); // 血量减少时的红色闪烁效果 FlashRedEffect(); // 血量减少时的红色闪烁效果
StopDoTween(0.2f); // 停止任何进行中的 DoTween 动画0.2s为示例值 StopDoTween(0.2f); // 停止任何进行中的 DoTween 动画0.2s为示例值