using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UIElements; public enum BulletType { Bullet, Lightning } public enum BulletMoveType {/// /// 子弹移动方式:点对点, /// PeerToPeer, /// /// 方向移动 /// PointToDirection } public class BulletData { [Header("子弹穿透次数")] public int NumberOfBulletPenetrations = 1; /// /// 子弹散射次数 /// [Header("子弹散射次数")] public int BulletScattering = 1; [Header("子弹连发次数")] public int BulletBurstTimes = 1; [Header("子弹连发间隔")] public float BulletBurstInterval ; [Header("子弹穿透衰减")] public float BulletPenetrationAttenuation = 0.2f; [Header("子弹飞行速度")] public float BulletSpeed = 5f; [Header("子弹攻击冷却")] public float BulletAttackCooldown = 1f; [Header("子弹伤害")] public float attack = 10; public BulletData() { } public BulletData(int numberOfBulletPenetrations, int bulletScattering, int bulletBurstTimes, float bulletBurstInterval, float bulletPenetrationAttenuation, float bulletSpeed, float bulletAttackCooldown) { NumberOfBulletPenetrations = numberOfBulletPenetrations; BulletScattering = bulletScattering; BulletBurstTimes = bulletBurstTimes; BulletBurstInterval = bulletBurstInterval; BulletPenetrationAttenuation = bulletPenetrationAttenuation; BulletSpeed = bulletSpeed; BulletAttackCooldown = bulletAttackCooldown; } public override string ToString() { return $"{nameof(NumberOfBulletPenetrations)}: {NumberOfBulletPenetrations}, {nameof(BulletScattering)}: {BulletScattering}, {nameof(BulletBurstTimes)}: {BulletBurstTimes}, {nameof(BulletBurstInterval)}: {BulletBurstInterval}, {nameof(BulletPenetrationAttenuation)}: {BulletPenetrationAttenuation}, {nameof(BulletSpeed)}: {BulletSpeed}, {nameof(BulletAttackCooldown)}: {BulletAttackCooldown}"; } } public class Bullet : MonoBehaviour { [Header("子弹发射角色对象")] public Role role; [Header("子弹发射范围对象")] public Attack attackObj; [Header("子弹类型")]public BulletType myBulletType; [Header("攻击类型")]public BulletMoveType bulletMoveType; [Header("子弹数据")] public BulletData bulletData =new BulletData(); private float timer = 0; private void Update() { switch (this.bulletMoveType) { //更具子弹的移动方式来移动 case BulletMoveType.PeerToPeer: this.gameObject.transform.Translate(Vector3.up * Time.deltaTime * bulletData.BulletSpeed); break; case BulletMoveType.PointToDirection: break; } timer += Time.deltaTime; if (timer>10f) { Destroy(this.gameObject); } } private void OnTriggerEnter2D(Collider2D collision) { Debug.Log("进入检测范围"); Role Crole = collision.gameObject.GetComponent(); if(Crole) { if(Crole.camp!= role.camp) { Debug.Log("进行攻击计算"); Crole.bloodLoss(new object[] { Crole, role.Attack + bulletData.attack, attackObj.damageTyp, role }); Destroy(this.gameObject); } } } }