69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
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();
|
|
}
|
|
}
|
|
} |