金蝙蝠
This commit is contained in:
parent
5788bda1d2
commit
5632ff401d
@ -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<enemy>().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<RunRangeBullet>();
|
||||
|
||||
// 设置子弹的基本信息
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
82
Role/RunRangeBullet.cs
Normal file
82
Role/RunRangeBullet.cs
Normal file
@ -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<Role>();
|
||||
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<Role>()), attackObj.damageTyp, role }, direction);
|
||||
Crole.FlashRedEffect();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerStay2D(Collider2D collision)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
11
Role/RunRangeBullet.cs.meta
Normal file
11
Role/RunRangeBullet.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af7db09576b90574e8902582dc2c0edc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user