건물 건설 모드 및 건설 인터랙션
This commit is contained in:
55
Assets/Scripts/GameBase/ConstructionSite.cs
Normal file
55
Assets/Scripts/GameBase/ConstructionSite.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI; // UI 사용을 위해 추가
|
||||
|
||||
public class ConstructionSite : MonoBehaviour
|
||||
{
|
||||
[Header("UI Settings")]
|
||||
[SerializeField] private GameObject uiPrefab; // 방금 만든 Canvas 프리팹
|
||||
[SerializeField] private Vector3 uiOffset = new Vector3(0, 2f, 0); // 머리 위 높이
|
||||
|
||||
private Slider _progressSlider;
|
||||
private GameObject _finalTurretPrefab;
|
||||
private float _buildTime;
|
||||
private float _currentProgress = 0f;
|
||||
|
||||
public void Initialize(GameObject finalPrefab, float time)
|
||||
{
|
||||
_finalTurretPrefab = finalPrefab;
|
||||
_buildTime = time;
|
||||
|
||||
// UI 생성 및 초기화
|
||||
if (uiPrefab != null)
|
||||
{
|
||||
GameObject uiObj = Instantiate(uiPrefab, transform.position + uiOffset, Quaternion.identity, transform);
|
||||
_progressSlider = uiObj.GetComponentInChildren<Slider>();
|
||||
if (_progressSlider != null)
|
||||
{
|
||||
_progressSlider.maxValue = 1f;
|
||||
_progressSlider.value = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AdvanceConstruction(float amount)
|
||||
{
|
||||
_currentProgress += amount;
|
||||
float ratio = _currentProgress / _buildTime;
|
||||
|
||||
// 슬라이더 업데이트
|
||||
if (_progressSlider != null)
|
||||
{
|
||||
_progressSlider.value = ratio;
|
||||
}
|
||||
|
||||
if (_currentProgress >= _buildTime)
|
||||
{
|
||||
CompleteBuild();
|
||||
}
|
||||
}
|
||||
|
||||
private void CompleteBuild()
|
||||
{
|
||||
Instantiate(_finalTurretPrefab, transform.position, transform.rotation);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user