타워 기능 추가 및 개선
This commit is contained in:
43
Assets/Scripts/Tower/TowerRangeOverlay.cs
Normal file
43
Assets/Scripts/Tower/TowerRangeOverlay.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TowerRangeOverlay : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject _rangeSprite;
|
||||
private TowerAttack _towerAttack;
|
||||
private AreaTowerAttack _areaTowerAttack;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_towerAttack = GetComponentInParent<TowerAttack>();
|
||||
_areaTowerAttack = GetComponentInParent<AreaTowerAttack>();
|
||||
ShowRange(false);
|
||||
}
|
||||
|
||||
public void UpdateRangeScale()
|
||||
{
|
||||
if (_rangeSprite == null) return;
|
||||
|
||||
float currentRange = 0;
|
||||
if (_towerAttack != null) currentRange = _towerAttack.range;
|
||||
else if (_areaTowerAttack != null) currentRange = _areaTowerAttack.range;
|
||||
|
||||
// 1. BuildManager가 건드린 현재 오브젝트(고스트 루트)의 스케일을 가져옵니다.
|
||||
Vector3 myScale = transform.localScale;
|
||||
|
||||
// 2. 월드 크기 고정 계산
|
||||
// 월드에서 보여야 할 지름은 (currentRange * 2)입니다.
|
||||
// 자식의 스케일 * 부모의 스케일 = 월드 스케일이므로,
|
||||
// 자식의 스케일 = (원하는 월드 스케일) / 부모의 스케일 입니다.
|
||||
float finalScaleX = (currentRange * 2f) / myScale.x;
|
||||
float finalScaleZ = (currentRange * 2f) / myScale.z;
|
||||
|
||||
// 3. 자식(Sprite)에게 계산된 스케일 적용
|
||||
_rangeSprite.transform.localScale = new Vector3(finalScaleX, finalScaleZ, 1f);
|
||||
}
|
||||
|
||||
public void ShowRange(bool show)
|
||||
{
|
||||
_rangeSprite.SetActive(show);
|
||||
if (show) UpdateRangeScale();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user