From f1d8219300474f47b57fcf3d3867062dfde97d80 Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Sat, 4 Jan 2025 14:17:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=A8=E8=98=91=E8=8F=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Role/Attack.cs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Role/Attack.cs b/Role/Attack.cs index 35a656b..4f78126 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -401,4 +401,40 @@ public class Attack : MonoBehaviour } } + + + public void ShanXingAttack()//扇形散射 + { + if (bulletPrefab == null) + { + Debug.LogError("子弹预制体为空"); + return; + } + + float halfAngle = Angle / 2f; // 半个散射角度范围 + float angleStep = Angle / (BulletNumber - 1); // 每个子弹之间的角度间隔 + + for (int i = 0; i < BulletNumber; i++) + { + // 改变子弹方向,根据角色自身的攻击范围来计算 + GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root); + Bullet bulletScript = BulletGamobj.GetComponent(); + + bulletScript.role = role; + bulletScript.attackObj = this; + bulletScript.bulletData.BulletSpeed *= (1 + roleBulletSpeedAdd); + bulletScript.Target = Target; + + // 计算当前子弹的发射角度 + float currentAngle = -halfAngle + angleStep * i; // 当前子弹的偏移角度 + + // 使用偏移角度调整子弹的发射方向 + Vector3 scatterDirection = Quaternion.Euler(0, 0, currentAngle) * direction; // 在当前方向上添加旋转 + + BulletGamobj.transform.up = scatterDirection; + BulletGamobj.transform.position = BulletStartPos.position; + bulltes.Add(BulletGamobj); + } + } + }