技能加上但是youbug
This commit is contained in:
parent
8da1a9bd84
commit
d124ad1e7c
@ -27,6 +27,9 @@ public class Attack : MonoBehaviour
|
|||||||
[Header("子弹起始点")] public Transform BulletStartPos;
|
[Header("子弹起始点")] public Transform BulletStartPos;
|
||||||
[Header("攻击速度")] public float AttackSpeed=1f;
|
[Header("攻击速度")] public float AttackSpeed=1f;
|
||||||
public Vector2 direction;
|
public Vector2 direction;
|
||||||
|
|
||||||
|
[Header("子弹速度加成")]public float roleBulletSpeedAdd=0f;
|
||||||
|
[Header("子弹数量")] public int BulletNumber = 1;
|
||||||
public float AttackScope
|
public float AttackScope
|
||||||
{
|
{
|
||||||
[DebuggerStepThrough]
|
[DebuggerStepThrough]
|
||||||
@ -82,8 +85,8 @@ public class Attack : MonoBehaviour
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
attack(targetRole);
|
/*attack(targetRole);
|
||||||
lastAttackTime = Time.time; // 更新上次攻击时间
|
lastAttackTime = Time.time; // 更新上次攻击时间*/
|
||||||
}
|
}
|
||||||
|
|
||||||
break; // 只攻击一个目标
|
break; // 只攻击一个目标
|
||||||
@ -113,7 +116,7 @@ public class Attack : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attack(Role targetRole)
|
/*public void attack(Role targetRole)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (bulletPrefab == null)
|
if (bulletPrefab == null)
|
||||||
@ -149,7 +152,7 @@ public class Attack : MonoBehaviour
|
|||||||
bulltes.Add(BulletGamobj);
|
bulltes.Add(BulletGamobj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -161,20 +164,19 @@ public class Attack : MonoBehaviour
|
|||||||
Debug.LogError("子弹预制体为空");
|
Debug.LogError("子弹预制体为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < bulletData.BulletScattering; i++)
|
|
||||||
{
|
for (int i = 0; i < BulletNumber; i++)
|
||||||
// 改变子弹方向,根据角色自身的攻击范围来计算
|
{
|
||||||
GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root);
|
// 改变子弹方向,根据角色自身的攻击范围来计算
|
||||||
BulletGamobj.GetComponent<Bullet>().role = role;
|
GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root);
|
||||||
BulletGamobj.GetComponent<Bullet>().attackObj = this;
|
BulletGamobj.GetComponent<Bullet>().role = role;
|
||||||
BulletGamobj.transform.up = direction;
|
BulletGamobj.GetComponent<Bullet>().attackObj = this;
|
||||||
BulletGamobj.transform.position = BulletStartPos.position;
|
BulletGamobj.GetComponent<Bullet>().bulletData.BulletSpeed *= (1 + roleBulletSpeedAdd);
|
||||||
bulltes.Add(BulletGamobj);
|
BulletGamobj.transform.up = direction;
|
||||||
}
|
BulletGamobj.transform.position = BulletStartPos.position;
|
||||||
|
bulltes.Add(BulletGamobj);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,21 +190,41 @@ public class Attack : MonoBehaviour
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//需要修改
|
||||||
|
|
||||||
|
|
||||||
if (bulletPrefab.GetComponent<Bullet>().myBulletType == BulletType.Spraying)
|
if (bulletPrefab.GetComponent<Bullet>().myBulletType == BulletType.Spraying)
|
||||||
{
|
{
|
||||||
GameObject BulletGamobj = GameObject.Instantiate(bulletPrefab, this.transform.root);
|
// 计算每个子弹之间的角度间隔
|
||||||
fireAni = BulletGamobj.GetComponentInChildren<Animator>();
|
float angleStep = BulletNumber > 1 ? 30f / (BulletNumber - 1) : 0f;
|
||||||
BulletGamobj.GetComponent<Bullet>().role = role;
|
// 计算起始角度,使得子弹整体居中
|
||||||
BulletGamobj.GetComponent<Bullet>().attackObj = this;
|
float startAngle = -30f / 2f;
|
||||||
|
|
||||||
// BulletGamobj.transform.up = direction;
|
for (int i = 0; i < BulletNumber; i++)
|
||||||
BulletGamobj.transform.position = new Vector2(transform.position.x + 0.15f, transform.position.y + 0.2f);
|
{
|
||||||
bulltes.Add(BulletGamobj);
|
// 计算当前子弹的旋转角度
|
||||||
return;
|
float currentAngle = startAngle + (angleStep * i);
|
||||||
|
|
||||||
|
// 生成子弹对象并设置父物体
|
||||||
|
GameObject bulletGameObj = GameObject.Instantiate(bulletPrefab, transform.root);
|
||||||
|
|
||||||
|
// 设置子弹的初始位置
|
||||||
|
bulletGameObj.transform.position = new Vector2(transform.position.x + 0.15f, transform.position.y + 0.2f);
|
||||||
|
|
||||||
|
// 设置子弹的角色和攻击者
|
||||||
|
Bullet bulletComponent = bulletGameObj.GetComponent<Bullet>();
|
||||||
|
if (bulletComponent != null)
|
||||||
|
{
|
||||||
|
bulletComponent.role = role;
|
||||||
|
bulletComponent.attackObj = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置子弹的旋转角度
|
||||||
|
bulletGameObj.transform.rotation = Quaternion.Euler(0, 0, currentAngle);
|
||||||
|
|
||||||
|
// 将生成的子弹添加到子弹列表中
|
||||||
|
bulltes.Add(bulletGameObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user