飘字修改
This commit is contained in:
parent
84ca89c647
commit
8fde270423
@ -97,14 +97,20 @@ public class Bullet : MonoBehaviour
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
Debug.Log("½øÈë¼ì²â·¶Î§");
|
||||
//Debug.Log("进入检测范围");
|
||||
Role Crole = collision.gameObject.GetComponent<Role>();
|
||||
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<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)
|
||||
{
|
||||
|
@ -48,16 +48,16 @@ public class Fun : Base
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 扣血 传入参数 目标,伤害值,攻击类型,使用者
|
||||
/// 扣血 传入参数 目标,伤害值,攻击类型,使用者,子弹射来的方向(0是右边,1是左边)
|
||||
/// </summary>
|
||||
/// <param name="objects"></param>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<SnowHpControl>().direction = HurtDirectin;
|
||||
go.GetComponent<SnowHpControl>().CreateText();
|
||||
go.GetComponent<Text>().text = (temp - hp).ToString(); // 显示伤害值
|
||||
FlashRedEffect(); // 血量减少时的红色闪烁效果
|
||||
StopDoTween(0.2f); // 停止任何进行中的 DoTween 动画,0.2s为示例值
|
||||
|
Loading…
Reference in New Issue
Block a user