From 5632ff401d104f1aec9efb62c09c39209c94d6e8 Mon Sep 17 00:00:00 2001 From: GL <2365963573@qq.com> Date: Sat, 4 Jan 2025 18:09:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=91=E8=9D=99=E8=9D=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Role/Attack.cs | 74 ++++++++++++++++++++++++++++++++- Role/RunRangeBullet.cs | 82 +++++++++++++++++++++++++++++++++++++ Role/RunRangeBullet.cs.meta | 11 +++++ 3 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 Role/RunRangeBullet.cs create mode 100644 Role/RunRangeBullet.cs.meta diff --git a/Role/Attack.cs b/Role/Attack.cs index 677711c..dbde790 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -41,6 +41,8 @@ public class Attack : MonoBehaviour [Header("攻击随机角度范围")] public float Angle=30; [Header("子弹分裂个数")] public int splitNum = 2; [Header("分裂子弹伤害")] public float SplitAttack = 10; + [Header("子弹围绕范围")] public float RunRange = 3f; + public bool isAttack = true; public bool flag = false; [HideInInspector] public float timer = 0; @@ -51,7 +53,7 @@ public class Attack : MonoBehaviour bulletData = new BulletData(); bulletData.BulletScattering = 1; - animator.SetFloat("AttackSpeed", AttackSpeed); + //animator.SetFloat("AttackSpeed", AttackSpeed); attackCooldown = transform.parent.GetComponent().AttackCD; @@ -316,7 +318,7 @@ public class Attack : MonoBehaviour public void SetAttackRange() { - if (attackCollider) + if (attackCollider&& role.AttackRange !=0) { // 设置碰撞体的半径 attackCollider.radius = role.AttackRange-1; @@ -443,5 +445,73 @@ public class Attack : MonoBehaviour } + private int lastBulletNumber = 0; // 记录上一次的 BulletNumber + + public void RunRangeattack() // 生成在周围 + { + if (bulletPrefab == null) + { + // Debug.LogError("子弹预制体为空"); + return; + } + + // 只有在 BulletNumber 变化时,才重新生成子弹 + if (BulletNumber != lastBulletNumber) + { + // 销毁现有的所有子弹 + if (bulltes.Count>0) + { + foreach (var bullet in bulltes) + { + Destroy(bullet); // 销毁子弹对象 + } + bulltes.Clear(); // 清空子弹列表 + } + + + // 计算子弹发射的圆周角度间隔 + float angleStep = 360f / BulletNumber; // 计算每个子弹之间的角度间隔 + + // 生成新的子弹 + for (int i = 0; i < BulletNumber; i++) + { + // 创建子弹实例 + GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root); + + // 获取Bullet组件 + RunRangeBullet bulletScript = BulletGamobj.GetComponent(); + + // 设置子弹的基本信息 + bulletScript.role = role; + bulletScript.attackObj = this; + bulletScript.bulletData.BulletSpeed *= (1 + roleBulletSpeedAdd); // 根据角色的加成调整子弹速度 + bulletScript.Target = Target; + + // 将新子弹加入子弹列表 + bulltes.Add(BulletGamobj); + + // 计算当前子弹的发射角度(基于子弹的索引) + float currentAngle = angleStep * i; // 当前子弹的发射角度 + + // 计算子弹的发射位置,使用极坐标来计算圆周上的位置 + float x = Mathf.Cos(Mathf.Deg2Rad * currentAngle) * RunRange; + float y = Mathf.Sin(Mathf.Deg2Rad * currentAngle) * RunRange; + Vector3 position = new Vector3(x, y, 0) + BulletStartPos.position; // 加上起始位置 + + // 计算子弹的发射方向,使用极坐标转换为单位向量 + Vector3 scatterDirection = new Vector3(Mathf.Cos(Mathf.Deg2Rad * currentAngle), Mathf.Sin(Mathf.Deg2Rad * currentAngle), 0); + + // 设置子弹的朝向和位置 + BulletGamobj.transform.up = scatterDirection; // 让子弹的"up"方向指向计算出的角度 + BulletGamobj.transform.position = position; // 更新子弹的位置 + } + + // 更新记录的 BulletNumber + lastBulletNumber = BulletNumber; + } + } + + + } diff --git a/Role/RunRangeBullet.cs b/Role/RunRangeBullet.cs new file mode 100644 index 0000000..7702c1e --- /dev/null +++ b/Role/RunRangeBullet.cs @@ -0,0 +1,82 @@ +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.UIElements; +using System.Linq; + + + + + +public class RunRangeBullet : Bullet +{ + + + private void Update() + { + + transform.RotateAround(attackObj.BulletStartPos.position, Vector3.forward, 20f * Time.deltaTime*bulletData.BulletSpeed); + + + } + + private void OnTriggerEnter2D(Collider2D collision) + { + Role Crole = collision.gameObject.GetComponent(); + if (Crole&&Target!= collision.gameObject) + { + if (Crole.camp != role.camp) + { + + + + + + foreach (var buff in role.storageBuff) + { + if (!Crole.PlayerBuff.Contains(buff)) + { + Crole.PlayerBuff.Add(buff); + } + } + + Crole.ApplyBuffs(); + + // Debug.Log(this.role.gameObject.name + "й"); + int direction = 0; + if (collision.transform.position.x > transform.position.x) //ӵ򵽵ߣƮʾұ + { + direction = 1; + } + Crole.bloodLoss(new object[] { Crole, role.DamageCreate(Crole.GetComponent()), attackObj.damageTyp, role }, direction); + Crole.FlashRedEffect(); + + + + + + + + + + + } + } + } + + + private void OnTriggerStay2D(Collider2D collision) + { + + } + + private void OnTriggerExit2D(Collider2D collision) + { + + } + + + +} diff --git a/Role/RunRangeBullet.cs.meta b/Role/RunRangeBullet.cs.meta new file mode 100644 index 0000000..b067f54 --- /dev/null +++ b/Role/RunRangeBullet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: af7db09576b90574e8902582dc2c0edc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: