攻击范围

This commit is contained in:
GL 2024-12-28 14:30:38 +08:00
parent 53e24b624e
commit e181aec8b1

View File

@ -38,6 +38,7 @@ public class Attack : MonoBehaviour
[Header("攻击范围图片")] public SpriteRenderer attackRangeSprite; [Header("攻击范围图片")] public SpriteRenderer attackRangeSprite;
[Header("攻击持续时间")] public float AttackStayTime;// [Header("攻击持续时间")] public float AttackStayTime;//
[Header("攻击目标")] public GameObject Target; [Header("攻击目标")] public GameObject Target;
[Header("攻击范围显示脚本")] public CharacterClick characterClick;
public bool isAttack = true; public bool isAttack = true;
public bool flag = false; public bool flag = false;
[HideInInspector] public float timer = 0; [HideInInspector] public float timer = 0;
@ -353,16 +354,15 @@ private void GenerateBullet(float angle, Vector2 startPos, Vector2 changePos)//
{ {
// 设置碰撞体的半径 // 设置碰撞体的半径
attackCollider.radius = role.AttackRange; 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) else if(attackColliderBox)
{ {