This commit is contained in:
GL 2025-01-06 16:15:06 +08:00
parent 2cb47878a0
commit 37c9725786
2 changed files with 64 additions and 13 deletions

View File

@ -44,6 +44,7 @@ public class Attack : MonoBehaviour
[Header("子弹围绕范围")] public float RunRange = 3f;
[Header("是否造成额外伤害")] public bool haveAddDamage = false;
[Header("额外伤害类型")] public DamageType AdddamageType=DamageType.magicDamage;
[Header("子弹爆炸范围")] public float BoomRange = 1;
public bool isAttack = true;
public bool flag = false;
[HideInInspector] public float timer = 0;

View File

@ -84,7 +84,7 @@ public class Bullet : MonoBehaviour
[Header("销毁时间,默认是10f")] public float BulletDeadTimer = 10f;
[Header("子弹动画")] public Animator animator;
[Header("子弹移动参数")] public bool IsMove = true;
[Header("×Óµ¯ÅöײÌå")] public Collider2D Collider2D;
[Header("子弹碰撞体")] public CircleCollider2D Collider2D;
[Header("子弹特效预制体")] public List<GameObject> effectPres = new List<GameObject>();
private float timer = 0;
[Header("子弹攻击数量")] public int NumberOfBulletAttacks = 1;
@ -92,6 +92,7 @@ public class Bullet : MonoBehaviour
[Header("子弹是否不锁定目标")] public bool noLockEnemy=false;
[Header("子弹是否会分裂")] public bool Cansplit = false;
[Header("分裂子弹的预制体")] public GameObject smallBulletPrefab;
[Header("子弹是否会爆炸")] public bool CanBoom = false;
private void Update()
{
switch (this.bulletMoveType)
@ -167,9 +168,10 @@ public class Bullet : MonoBehaviour
{
direction = 1;
}
if (!CanBoom)//判断子弹是否会爆炸
{
Crole.bloodLoss(new object[] { Crole, role.DamageCreate(Crole.GetComponent<Role>()), attackObj.damageTyp, role }, direction);
attackObj.bulltes.Remove(this.gameObject);
if (myBulletType != BulletType.Spraying)
{
@ -189,6 +191,20 @@ public class Bullet : MonoBehaviour
}
}
}
else
{
if (animator!=null)
{
IsMove = false; //停止移动
Collider2D.enabled = false; //关闭碰撞体
transform.position = collision.transform.position;
animator.SetTrigger("Boom");
}
}
if (bulletAttributes == BulletAttributes.Not) //无属性
{
@ -319,4 +335,38 @@ public class Bullet : MonoBehaviour
}
}
}
public void BulletBoom() // 子弹爆炸
{
// 扩展碰撞体的大小,模拟爆炸范围
float explosionRadius = attackObj.BoomRange; // 设置爆炸的半径大小
// 检测爆炸范围内的敌人
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(transform.position, explosionRadius);
foreach (var enemyCollider in hitEnemies)
{
Role enemyRole = enemyCollider.gameObject.GetComponent<Role>();
if (enemyRole != null && enemyRole.camp != role.camp) // 如果是敌人并且属于不同的阵营
{
// 计算伤害值,可以根据子弹的类型或其他参数来调整
float damage = role.DamageCreate(enemyRole);
// 扣血操作
enemyRole.bloodLoss(new object[] { enemyRole, damage, attackObj.damageTyp, role });
enemyRole.FlashRedEffect();
}
}
// 销毁当前子弹
attackObj.bulltes.Remove(this.gameObject);
Destroy(this.gameObject);
}
}