金蛾子弹

This commit is contained in:
GL 2025-01-09 11:56:13 +08:00
parent e944cf9869
commit e79bd2ada7
2 changed files with 142 additions and 0 deletions

131
Role/jez_Bullet.cs Normal file
View File

@ -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<Role>();
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<Role>()), attackObj.damageTyp, role }, direction);
Crole.FlashRedEffect();
}
}
}
private void OnTriggerStay2D(Collider2D collision)
{
}
private void OnTriggerExit2D(Collider2D collision)
{
}
}

11
Role/jez_Bullet.cs.meta Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e31ebd3b0b4200f41b0f751131f92e72
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: