건물 체력 시스템 추가
건물 시야 시스템은 기본 건물데이터에 통합
This commit is contained in:
69
Assets/Scripts/BuildingDamageTest.cs
Normal file
69
Assets/Scripts/BuildingDamageTest.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Northbound
|
||||
{
|
||||
/// <summary>
|
||||
/// 건물에 데미지를 주는 테스트/공격 시스템
|
||||
/// </summary>
|
||||
public class BuildingDamageTest : MonoBehaviour
|
||||
{
|
||||
[Header("Damage Settings")]
|
||||
public int damageAmount = 10;
|
||||
public float damageInterval = 1f;
|
||||
public KeyCode damageKey = KeyCode.F;
|
||||
|
||||
[Header("Target")]
|
||||
public float maxDistance = 10f;
|
||||
public LayerMask buildingLayer;
|
||||
|
||||
private float _lastDamageTime;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(damageKey))
|
||||
{
|
||||
TryDamageBuilding();
|
||||
}
|
||||
|
||||
// 자동 데미지 (테스트용)
|
||||
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(damageKey))
|
||||
{
|
||||
if (Time.time - _lastDamageTime >= damageInterval)
|
||||
{
|
||||
TryDamageBuilding();
|
||||
_lastDamageTime = Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TryDamageBuilding()
|
||||
{
|
||||
// 카메라에서 레이캐스트
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, maxDistance, buildingLayer))
|
||||
{
|
||||
Building building = hit.collider.GetComponentInParent<Building>();
|
||||
|
||||
if (building != null)
|
||||
{
|
||||
ulong attackerId = NetworkManager.Singleton != null && NetworkManager.Singleton.IsClient
|
||||
? NetworkManager.Singleton.LocalClientId
|
||||
: 0;
|
||||
|
||||
building.TakeDamage(damageAmount, attackerId);
|
||||
Debug.Log($"<color=yellow>[Test] {building.buildingData?.buildingName ?? "건물"}에게 {damageAmount} 데미지!</color>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.BeginArea(new Rect(10, 10, 300, 100));
|
||||
GUILayout.Label($"[{damageKey}] 건물에 {damageAmount} 데미지");
|
||||
GUILayout.Label($"[Shift + {damageKey}] 연속 데미지");
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user