From cd7f839004ff7f4e4e003a19dccfa2ae1df4a928 Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Thu, 26 Dec 2024 11:19:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AEbug=EF=BC=8C=E7=81=AB=E7=84=B0?= =?UTF-8?q?=E5=88=86=E5=8F=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Role/Attack.cs | 94 +++++++++++++++++++++++++++++++++----------------- Role/Bullet.cs | 2 +- Role/Role.cs | 10 +++--- 3 files changed, 68 insertions(+), 38 deletions(-) diff --git a/Role/Attack.cs b/Role/Attack.cs index 0084ece..ddf0528 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -22,7 +22,8 @@ public class Attack : MonoBehaviour public List bulltes = new List(); [Header("角色动画控制器")] public Animator animator; - [Header("火焰动画控制器")] public Animator fireAni; + //[Header("火焰动画控制器")] public Animator fireAni; + [Header("火焰动画控制器")] public List fireAnis; [Header("子弹起始点")] public Transform BulletStartPos; [Header("攻击速度")] public float AttackSpeed=1f; @@ -183,54 +184,83 @@ public class Attack : MonoBehaviour public void Fireattack() { - if (bulletPrefab == null) { Debug.LogError("子弹预制体为空"); return; } - //需要修改 + // 检查子弹类型是否为 Spraying if (bulletPrefab.GetComponent().myBulletType == BulletType.Spraying) { - // 计算每个子弹之间的角度间隔 - float angleStep = BulletNumber > 1 ? 30f / (BulletNumber - 1) : 0f; - // 计算起始角度,使得子弹整体居中 - float startAngle = -30f / 2f; - - for (int i = 0; i < BulletNumber; i++) + // 根据 BulletNumber 生成不同数量和旋转角度的子弹 + switch (BulletNumber) { - // 计算当前子弹的旋转角度 - float currentAngle = startAngle + (angleStep * i); + case 1: + // 生成一个不旋转的子弹 + GenerateBullet(0f, BulletStartPos.position, new Vector2(0, 0)); + break; - // 生成子弹对象并设置父物体 - GameObject bulletGameObj = GameObject.Instantiate(bulletPrefab, transform.root); + case 3: + // 生成三个子弹:一个不旋转,一个向上旋转30度,一个向下旋转30度 + GenerateBullet(-30f, BulletStartPos.position, new Vector2(0, -0.2f)); + GenerateBullet(0f, BulletStartPos.position, new Vector2(0, 0)); + GenerateBullet(30f, BulletStartPos.position, new Vector2(0, 0.2f)); + break; - // 设置子弹的初始位置 - 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); + default: + // 可选:处理其他 BulletNumber 值的情况 + Debug.LogWarning($"BulletNumber 为 {BulletNumber} 时未定义的生成逻辑。"); + break; } } - - } + +private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos)//角度,旋转中心点 + { + // 实例化子弹对象并设置父物体为 transform.root + GameObject bulletGameObj = GameObject.Instantiate(bulletPrefab, transform.root); + + // 获取动画组件(如果需要的话) + fireAnis.Add(bulletGameObj.GetComponentInChildren()); + + // 设置子弹的初始位置,保持偏移量 + 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; + } + + // 计算子弹相对于旋转中心的偏移 + Vector2 direction = bulletGameObj.transform.position - (Vector3)startPos; + + // 旋转偏移 + direction = Quaternion.Euler(0, 0, angle) * direction; + + // 更新子弹的位置 + bulletGameObj.transform.position = startPos + direction; + + // 设置子弹的旋转角度 + bulletGameObj.transform.rotation = Quaternion.Euler(0, 0, angle); + bulletGameObj.transform.position = bulletGameObj.transform.position + (Vector3)changePos; + + // 将生成的子弹添加到子弹列表中 + bulltes.Add(bulletGameObj); + } + + public void EndFire() { - fireAni.SetInteger("State", 1); + foreach (Animator ani in fireAnis) + { + ani.SetInteger("State", 1); + } + fireAnis.Clear(); //Debug.Log("停止火焰"); } diff --git a/Role/Bullet.cs b/Role/Bullet.cs index 17edaf5..ffe27e2 100644 --- a/Role/Bullet.cs +++ b/Role/Bullet.cs @@ -146,7 +146,7 @@ public class Bullet : MonoBehaviour Crole.ApplyBuffs(); - Debug.Log(this.role.gameObject.name + "й"); + // Debug.Log(this.role.gameObject.name + "й"); int direction = 0; if (collision.transform.position.x > transform.position.x) //ӵ򵽵ߣƮʾұ { diff --git a/Role/Role.cs b/Role/Role.cs index 782f5a6..42c9793 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -508,29 +508,29 @@ public class Role : Fun } hurt *= (1 + mySkillUp.DamageUp); - Debug.LogError("˺ӳɣ"+ mySkillUp.DamageUp); + // Debug.LogError("˺ӳɣ"+ mySkillUp.DamageUp); if (Target.hasfalg(CharacterFlags.big)) // Ǵ͵ { hurt*=(1+mySkillUp.DamageOfBig); - Debug.LogError("͵˼ӳ"); + //Debug.LogError("͵˼ӳ"); } if (Target.hasfalg(CharacterFlags.min)) // С͵ { hurt *= (1 + mySkillUp.DamageOfMin); - Debug.LogError("С͵˼ӳ"); + //Debug.LogError("С͵˼ӳ"); } if (Target.hasfalg(CharacterFlags.fly)) // Ƿе { hurt *= (1 + mySkillUp.DamageOfSky); - Debug.LogError("е˼ӳ"); + //Debug.LogError("е˼ӳ"); } if (Target.hasfalg(CharacterFlags.land)) // ǵ { hurt *= (1 + mySkillUp.DamageOfland); - Debug.LogError("˼ӳ"); + //Debug.LogError("˼ӳ"); }