2026-01-29 06:58:38 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class PlayerInteraction : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
[Header("--- 설정 ---")]
|
|
|
|
|
|
[SerializeField] private float interactRange = 3f;
|
|
|
|
|
|
[SerializeField] private LayerMask itemLayer;
|
|
|
|
|
|
[SerializeField] private Transform handSlot;
|
|
|
|
|
|
[SerializeField] private Stats playerStats;
|
|
|
|
|
|
|
|
|
|
|
|
private EquippableItem _currentWeapon;
|
|
|
|
|
|
public EquippableItem CurrentWeapon => _currentWeapon;
|
|
|
|
|
|
|
|
|
|
|
|
public void TryInteract()
|
|
|
|
|
|
{
|
|
|
|
|
|
Collider[] hits = Physics.OverlapSphere(transform.position, interactRange, itemLayer);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var hit in hits)
|
|
|
|
|
|
{
|
2026-01-29 16:11:10 +00:00
|
|
|
|
// 1. 무기 상호작용
|
2026-01-29 06:58:38 +00:00
|
|
|
|
if (hit.TryGetComponent<EquippableItem>(out var item))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (playerStats.Strength >= item.Config.RequiredStrength)
|
|
|
|
|
|
{
|
2026-01-29 16:11:10 +00:00
|
|
|
|
EquipWeapon(item);
|
2026-01-29 06:58:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2026-01-29 16:11:10 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// ⭐ [핵심 수정] 힘이 부족하면 카메라를 흔듭니다!
|
|
|
|
|
|
CinemachineShake.Instance?.ShakeNoNo();
|
|
|
|
|
|
Debug.Log($"힘 부족! 필요: {item.Config.RequiredStrength}, 현재: {playerStats.Strength}");
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 포션 상호작용
|
|
|
|
|
|
if (hit.TryGetComponent<HealthPotion>(out var potion))
|
|
|
|
|
|
{
|
|
|
|
|
|
potion.Use(GetComponent<PlayerHealth>());
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 제단 상호작용
|
|
|
|
|
|
if (hit.TryGetComponent<HealthAltar>(out var altar))
|
|
|
|
|
|
{
|
|
|
|
|
|
altar.Use(GetComponent<PlayerHealth>());
|
|
|
|
|
|
break;
|
2026-01-29 06:58:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-29 16:11:10 +00:00
|
|
|
|
private void EquipWeapon(EquippableItem item)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_currentWeapon != null) _currentWeapon.OnDropped(transform.forward);
|
|
|
|
|
|
_currentWeapon = item;
|
|
|
|
|
|
_currentWeapon.OnPickedUp(handSlot);
|
|
|
|
|
|
playerStats.UpdateWeaponWeight(item.Config.RequiredStrength);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-29 06:58:38 +00:00
|
|
|
|
public void ClearCurrentWeapon() => _currentWeapon = null;
|
|
|
|
|
|
}
|