diff --git a/Role/Attack.cs b/Role/Attack.cs index 1bc5b8c..117a0e6 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -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(); @@ -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().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()); // 设置子弹的初始位置,保持偏移量 - bulletGameObj.transform.position = new Vector2(transform.position.x+1.75f, transform.position.y + 0.2f); + bulletGameObj.GetComponent().role = role; bulletGameObj.GetComponent().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); + // 将生成的子弹添加到子弹列表中 diff --git a/Role/Role.cs b/Role/Role.cs index ae9e20e..9b4a4b6 100644 --- a/Role/Role.cs +++ b/Role/Role.cs @@ -536,7 +536,7 @@ public class Role : Fun } - return hurt; + return Mathf.Round(hurt); } public virtual void SlowDown(float slowFactor, float duration)