diff --git a/Role/Attack.cs b/Role/Attack.cs index 0d6f6a3..57c57c5 100644 --- a/Role/Attack.cs +++ b/Role/Attack.cs @@ -38,6 +38,7 @@ public class Attack : MonoBehaviour [Header("攻击范围图片")] public SpriteRenderer attackRangeSprite; [Header("攻击持续时间")] public float AttackStayTime;// [Header("攻击目标")] public GameObject Target; + [Header("攻击范围显示脚本")] public CharacterClick characterClick; public bool isAttack = true; public bool flag = false; [HideInInspector] public float timer = 0; @@ -353,16 +354,15 @@ private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos)// { // 设置碰撞体的半径 attackCollider.radius = role.AttackRange; - - - // 获取攻击范围图片的原始直径 (SpriteRenderer的bounds.size.x) - float spriteDiameter = attackRangeSprite.bounds.size.x; + + + // 计算缩放因子,使得图片的直径与碰撞体的直径匹配 - float scaleFactor = role.AttackRange * 2f / spriteDiameter; // * 2f 因为 radius 是半径,图片的尺寸通常是直径 + characterClick.OrSizeX = role.AttackRange * 2f / characterClick.OrSizeX; // * 2f 因为 radius 是半径,图片的尺寸通常是直径 + - // 设置图片的缩放 - attackRangeSprite.transform.localScale = new Vector3(scaleFactor, scaleFactor, 1f); + } else if(attackColliderBox) {