修bug,火焰分叉
This commit is contained in:
parent
badd008edc
commit
cd7f839004
@ -22,7 +22,8 @@ public class Attack : MonoBehaviour
|
|||||||
public List<GameObject> bulltes = new List<GameObject>();
|
public List<GameObject> bulltes = new List<GameObject>();
|
||||||
|
|
||||||
[Header("角色动画控制器")] public Animator animator;
|
[Header("角色动画控制器")] public Animator animator;
|
||||||
[Header("火焰动画控制器")] public Animator fireAni;
|
//[Header("火焰动画控制器")] public Animator fireAni;
|
||||||
|
[Header("火焰动画控制器")] public List<Animator> fireAnis;
|
||||||
|
|
||||||
[Header("子弹起始点")] public Transform BulletStartPos;
|
[Header("子弹起始点")] public Transform BulletStartPos;
|
||||||
[Header("攻击速度")] public float AttackSpeed=1f;
|
[Header("攻击速度")] public float AttackSpeed=1f;
|
||||||
@ -183,54 +184,83 @@ public class Attack : MonoBehaviour
|
|||||||
|
|
||||||
public void Fireattack()
|
public void Fireattack()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (bulletPrefab == null)
|
if (bulletPrefab == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("子弹预制体为空");
|
Debug.LogError("子弹预制体为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//需要修改
|
// 检查子弹类型是否为 Spraying
|
||||||
if (bulletPrefab.GetComponent<Bullet>().myBulletType == BulletType.Spraying)
|
if (bulletPrefab.GetComponent<Bullet>().myBulletType == BulletType.Spraying)
|
||||||
{
|
{
|
||||||
// 计算每个子弹之间的角度间隔
|
// 根据 BulletNumber 生成不同数量和旋转角度的子弹
|
||||||
float angleStep = BulletNumber > 1 ? 30f / (BulletNumber - 1) : 0f;
|
switch (BulletNumber)
|
||||||
// 计算起始角度,使得子弹整体居中
|
|
||||||
float startAngle = -30f / 2f;
|
|
||||||
|
|
||||||
for (int i = 0; i < BulletNumber; i++)
|
|
||||||
{
|
{
|
||||||
// 计算当前子弹的旋转角度
|
case 1:
|
||||||
float currentAngle = startAngle + (angleStep * i);
|
// 生成一个不旋转的子弹
|
||||||
|
GenerateBullet(0f, BulletStartPos.position, new Vector2(0, 0));
|
||||||
|
break;
|
||||||
|
|
||||||
// 生成子弹对象并设置父物体
|
case 3:
|
||||||
GameObject bulletGameObj = GameObject.Instantiate(bulletPrefab, transform.root);
|
// 生成三个子弹:一个不旋转,一个向上旋转30度,一个向下旋转30度
|
||||||
|
GenerateBullet(-30f, BulletStartPos.position, new Vector2(0, -0.2f));
|
||||||
|
GenerateBullet(0f, BulletStartPos.position, new Vector2(0, 0));
|
||||||
|
GenerateBullet(30f, BulletStartPos.position, new Vector2(0, 0.2f));
|
||||||
|
break;
|
||||||
|
|
||||||
// 设置子弹的初始位置
|
default:
|
||||||
bulletGameObj.transform.position = new Vector2(transform.position.x + 0.15f, transform.position.y + 0.2f);
|
// 可选:处理其他 BulletNumber 值的情况
|
||||||
|
Debug.LogWarning($"BulletNumber 为 {BulletNumber} 时未定义的生成逻辑。");
|
||||||
// 设置子弹的角色和攻击者
|
break;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos)//角度,旋转中心点
|
||||||
|
{
|
||||||
|
// 实例化子弹对象并设置父物体为 transform.root
|
||||||
|
GameObject bulletGameObj = GameObject.Instantiate(bulletPrefab, transform.root);
|
||||||
|
|
||||||
|
// 获取动画组件(如果需要的话)
|
||||||
|
fireAnis.Add(bulletGameObj.GetComponentInChildren<Animator>());
|
||||||
|
|
||||||
|
// 设置子弹的初始位置,保持偏移量
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算子弹相对于旋转中心的偏移
|
||||||
|
Vector2 direction = bulletGameObj.transform.position - (Vector3)startPos;
|
||||||
|
|
||||||
|
// 旋转偏移
|
||||||
|
direction = Quaternion.Euler(0, 0, angle) * direction;
|
||||||
|
|
||||||
|
// 更新子弹的位置
|
||||||
|
bulletGameObj.transform.position = startPos + direction;
|
||||||
|
|
||||||
|
// 设置子弹的旋转角度
|
||||||
|
bulletGameObj.transform.rotation = Quaternion.Euler(0, 0, angle);
|
||||||
|
bulletGameObj.transform.position = bulletGameObj.transform.position + (Vector3)changePos;
|
||||||
|
|
||||||
|
// 将生成的子弹添加到子弹列表中
|
||||||
|
bulltes.Add(bulletGameObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void EndFire()
|
public void EndFire()
|
||||||
{
|
{
|
||||||
fireAni.SetInteger("State", 1);
|
foreach (Animator ani in fireAnis)
|
||||||
|
{
|
||||||
|
ani.SetInteger("State", 1);
|
||||||
|
}
|
||||||
|
fireAnis.Clear();
|
||||||
//Debug.Log("停止火焰");
|
//Debug.Log("停止火焰");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ public class Bullet : MonoBehaviour
|
|||||||
|
|
||||||
Crole.ApplyBuffs();
|
Crole.ApplyBuffs();
|
||||||
|
|
||||||
Debug.Log(this.role.gameObject.name + "进行攻击计算");
|
// Debug.Log(this.role.gameObject.name + "进行攻击计算");
|
||||||
int direction = 0;
|
int direction = 0;
|
||||||
if (collision.transform.position.x > transform.position.x) //子弹打到敌人左边,飘字显示到右边
|
if (collision.transform.position.x > transform.position.x) //子弹打到敌人左边,飘字显示到右边
|
||||||
{
|
{
|
||||||
|
10
Role/Role.cs
10
Role/Role.cs
@ -508,29 +508,29 @@ public class Role : Fun
|
|||||||
}
|
}
|
||||||
|
|
||||||
hurt *= (1 + mySkillUp.DamageUp);
|
hurt *= (1 + mySkillUp.DamageUp);
|
||||||
Debug.LogError("伤害加成:"+ mySkillUp.DamageUp);
|
// Debug.LogError("伤害加成:"+ mySkillUp.DamageUp);
|
||||||
if (Target.hasfalg(CharacterFlags.big)) // 如果是大型敌人
|
if (Target.hasfalg(CharacterFlags.big)) // 如果是大型敌人
|
||||||
{
|
{
|
||||||
hurt*=(1+mySkillUp.DamageOfBig);
|
hurt*=(1+mySkillUp.DamageOfBig);
|
||||||
Debug.LogError("大型敌人加成");
|
//Debug.LogError("大型敌人加成");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Target.hasfalg(CharacterFlags.min)) // 如果是小型敌人
|
if (Target.hasfalg(CharacterFlags.min)) // 如果是小型敌人
|
||||||
{
|
{
|
||||||
hurt *= (1 + mySkillUp.DamageOfMin);
|
hurt *= (1 + mySkillUp.DamageOfMin);
|
||||||
Debug.LogError("小型敌人加成");
|
//Debug.LogError("小型敌人加成");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Target.hasfalg(CharacterFlags.fly)) // 如果是飞行敌人
|
if (Target.hasfalg(CharacterFlags.fly)) // 如果是飞行敌人
|
||||||
{
|
{
|
||||||
hurt *= (1 + mySkillUp.DamageOfSky);
|
hurt *= (1 + mySkillUp.DamageOfSky);
|
||||||
Debug.LogError("飞行敌人加成");
|
//Debug.LogError("飞行敌人加成");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Target.hasfalg(CharacterFlags.land)) // 如果是地面敌人
|
if (Target.hasfalg(CharacterFlags.land)) // 如果是地面敌人
|
||||||
{
|
{
|
||||||
hurt *= (1 + mySkillUp.DamageOfland);
|
hurt *= (1 + mySkillUp.DamageOfland);
|
||||||
Debug.LogError("地面敌人加成");
|
//Debug.LogError("地面敌人加成");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user