火焰长度

This commit is contained in:
GL 2024-12-27 11:38:49 +08:00
parent 722bec67c7
commit 8632b38362
2 changed files with 22 additions and 13 deletions

View File

@ -30,6 +30,7 @@ public class Attack : MonoBehaviour
public Vector2 direction;
[Header("子弹速度加成")]public float roleBulletSpeedAdd=0f;
//[Header("子弹长度")] public float scaleFactor;
[Header("子弹数量")] public int BulletNumber = 1;
[Header("攻击碰撞体")] public CircleCollider2D attackCollider;
[Header("矩形攻击碰撞体")] public BoxCollider2D attackColliderBox;
@ -52,6 +53,7 @@ public class Attack : MonoBehaviour
//AttackScope = attackScope;
bulletData = new BulletData();
bulletData.BulletScattering = 1;
animator.SetFloat("AttackSpeed",AttackSpeed);
//CircleCollider2D circleCollider2D = GetComponent<CircleCollider2D>();
@ -241,9 +243,9 @@ public class Attack : MonoBehaviour
case 3:
// 生成三个子弹一个不旋转一个向上旋转30度一个向下旋转30度
GenerateBullet(-30f, BulletStartPos.position, new Vector2(0, -0.2f));
GenerateBullet(-35f, BulletStartPos.position, new Vector2(0, -0.25f));
GenerateBullet(0f, BulletStartPos.position, new Vector2(0, 0));
GenerateBullet(30f, BulletStartPos.position, new Vector2(0, 0.2f));
GenerateBullet(35f, BulletStartPos.position, new Vector2(0, 0.25f));
break;
default:
@ -255,21 +257,32 @@ public class Attack : MonoBehaviour
}
private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos,float scaleFactor=1)//角度,旋转中心点
private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos)//角度,旋转中心点
{
// 实例化子弹对象并设置父物体为 transform.root
GameObject bulletGameObj = GameObject.Instantiate(bulletPrefab, transform.root);
// 获取子弹的原始宽度
float originalWidth = bulletGameObj.GetComponentInChildren<SpriteRenderer>().bounds.size.x;
// 设置子弹的缩放
bulletGameObj.transform.localScale = new Vector2(scaleFactor, 1);
// 设置子弹的缩放
if (role.AttackRange / 2>1)
{
bulletGameObj.transform.localScale = new Vector2(role.AttackRange / 2, role.AttackRange / 3);
// 计算缩放后的偏移量
float offsetX = (originalWidth * (role.AttackRange / 2)) / 4f+0.15f;
// 调整子弹的位置,确保左边界不变
bulletGameObj.transform.position = new Vector2(bulletGameObj.transform.position.x + offsetX, bulletGameObj.transform.position.y);
}
bulletGameObj.transform.position = new Vector2(bulletGameObj.transform.position.x + 1.75f, bulletGameObj.transform.position.y + 0.2f);
// 获取动画组件(如果需要的话)
fireAnis.Add(bulletGameObj.GetComponentInChildren<Animator>());
// 设置子弹的初始位置,保持偏移量
bulletGameObj.transform.position = new Vector2(transform.position.x+1.75f, transform.position.y + 0.2f);
bulletGameObj.GetComponent<Bullet>().role = role;
bulletGameObj.GetComponent<Bullet>().attackObj = this;
@ -289,11 +302,7 @@ private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos,flo
bulletGameObj.transform.position = bulletGameObj.transform.position + (Vector3)changePos;
// 计算缩放后的偏移量
float offsetX = (originalWidth * (scaleFactor - 1)) / 2f;
// 调整子弹的位置,确保左边界不变
bulletGameObj.transform.position = new Vector2(bulletGameObj.transform.position.x + offsetX, bulletGameObj.transform.position.y);
// 将生成的子弹添加到子弹列表中

View File

@ -536,7 +536,7 @@ public class Role : Fun
}
return hurt;
return Mathf.Round(hurt);
}
public virtual void SlowDown(float slowFactor, float duration)