diff --git a/Role/jez_Bullet.cs b/Role/jez_Bullet.cs new file mode 100644 index 0000000..2be7fad --- /dev/null +++ b/Role/jez_Bullet.cs @@ -0,0 +1,131 @@ +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.UIElements; +using System.Linq; + + + + + +public class jez_Bullet : Bullet +{ + + private bool isReturning = false; // 标记当前是否在返回阶段 + private Vector3 startPosition; // 子弹的起始位置 + private Vector3 targetPosition; // 子弹的目标位置 + + + private void Start() + { + // 记录子弹初始位置 + startPosition = transform.position; + + // 计算子弹的目标位置(向前移动一定距离) + targetPosition = startPosition + transform.up * (role.AttackRange+2); + } + + private void Update() + { + switch (this.bulletMoveType) + { + // 根据子弹的移动方式来移动 + case BulletMoveType.PeerToPeer: + if (IsMove) + { + if (!isReturning) + { + // 向目标点移动 + transform.position = Vector3.MoveTowards(transform.position, targetPosition, Time.deltaTime * bulletData.BulletSpeed); + + // 如果到达目标点,开始返回 + if (Vector3.Distance(transform.position, targetPosition) < 0.1f) + { + isReturning = true; // 切换到返回阶段 + } + } + else + { + // 返回到起始位置 + transform.position = Vector3.MoveTowards(transform.position, startPosition, Time.deltaTime * bulletData.BulletSpeed); + + // 如果到达起始位置,停止移动或执行其他逻辑 + if (Vector3.Distance(transform.position, startPosition) < 0.1f) + { + IsMove = false; // 停止移动 + Destroy(this.gameObject); + Debug.Log("回旋镖返回到起始位置"); + } + } + } + break; + + case BulletMoveType.PointToDirection: + // 实现其他移动方式的逻辑 + break; + + case BulletMoveType.Scope: + // 实现其他移动方式的逻辑 + break; + } + } + + private void OnTriggerEnter2D(Collider2D collision) + { + Role Crole = collision.gameObject.GetComponent(); + if (Crole) + { + 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/jez_Bullet.cs.meta b/Role/jez_Bullet.cs.meta new file mode 100644 index 0000000..5e96308 --- /dev/null +++ b/Role/jez_Bullet.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e31ebd3b0b4200f41b0f751131f92e72 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: