diff --git a/Role/Attack.cs b/Role/Attack.cs index afad215..0084ece 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -27,6 +27,9 @@ public class Attack : MonoBehaviour [Header("子弹起始点")] public Transform BulletStartPos; [Header("攻击速度")] public float AttackSpeed=1f; public Vector2 direction; + + [Header("子弹速度加成")]public float roleBulletSpeedAdd=0f; + [Header("子弹数量")] public int BulletNumber = 1; public float AttackScope { [DebuggerStepThrough] @@ -82,8 +85,8 @@ public class Attack : MonoBehaviour } else { - attack(targetRole); - lastAttackTime = Time.time; // 更新上次攻击时间 + /*attack(targetRole); + lastAttackTime = Time.time; // 更新上次攻击时间*/ } break; // 只攻击一个目标 @@ -113,7 +116,7 @@ public class Attack : MonoBehaviour } } - public void attack(Role targetRole) + /*public void attack(Role targetRole) { if (bulletPrefab == null) @@ -149,7 +152,7 @@ public class Attack : MonoBehaviour bulltes.Add(BulletGamobj); } } - } + }*/ @@ -161,20 +164,19 @@ public class Attack : MonoBehaviour Debug.LogError("子弹预制体为空"); return; } - - - - for (int i = 0; i < bulletData.BulletScattering; i++) - { - // 改变子弹方向,根据角色自身的攻击范围来计算 - GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root); - BulletGamobj.GetComponent().role = role; - BulletGamobj.GetComponent().attackObj = this; - BulletGamobj.transform.up = direction; - BulletGamobj.transform.position = BulletStartPos.position; - bulltes.Add(BulletGamobj); - } + + for (int i = 0; i < BulletNumber; i++) + { + // 改变子弹方向,根据角色自身的攻击范围来计算 + GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root); + BulletGamobj.GetComponent().role = role; + BulletGamobj.GetComponent().attackObj = this; + BulletGamobj.GetComponent().bulletData.BulletSpeed *= (1 + roleBulletSpeedAdd); + BulletGamobj.transform.up = direction; + BulletGamobj.transform.position = BulletStartPos.position; + bulltes.Add(BulletGamobj); + } } @@ -188,21 +190,41 @@ public class Attack : MonoBehaviour return; } - - - + //需要修改 if (bulletPrefab.GetComponent().myBulletType == BulletType.Spraying) { - GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root); - fireAni = BulletGamobj.GetComponentInChildren(); - BulletGamobj.GetComponent().role = role; - BulletGamobj.GetComponent().attackObj = this; - - // BulletGamobj.transform.up = direction; - BulletGamobj.transform.position = new Vector2(transform.position.x + 0.15f, transform.position.y + 0.2f); - bulltes.Add(BulletGamobj); - return; + // 计算每个子弹之间的角度间隔 + float angleStep = BulletNumber > 1 ? 30f / (BulletNumber - 1) : 0f; + // 计算起始角度,使得子弹整体居中 + float startAngle = -30f / 2f; + + for (int i = 0; i < BulletNumber; i++) + { + // 计算当前子弹的旋转角度 + float currentAngle = startAngle + (angleStep * i); + + // 生成子弹对象并设置父物体 + GameObject bulletGameObj = GameObject.Instantiate(bulletPrefab, transform.root); + + // 设置子弹的初始位置 + bulletGameObj.transform.position = new Vector2(transform.position.x + 0.15f, transform.position.y + 0.2f); + + // 设置子弹的角色和攻击者 + Bullet bulletComponent = bulletGameObj.GetComponent(); + if (bulletComponent != null) + { + bulletComponent.role = role; + bulletComponent.attackObj = this; + } + + // 设置子弹的旋转角度 + bulletGameObj.transform.rotation = Quaternion.Euler(0, 0, currentAngle); + + // 将生成的子弹添加到子弹列表中 + bulltes.Add(bulletGameObj); + } } + }