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)
|
|
|
|
|
|
{
|
|
|
|
|
|
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-02-01 15:49:12 +00:00
|
|
|
|
else { CinemachineShake.Instance?.ShakeNoNo(); continue; }
|
2026-01-29 06:58:38 +00:00
|
|
|
|
}
|
2026-02-01 15:49:12 +00:00
|
|
|
|
if (hit.TryGetComponent<HealthPotion>(out var potion)) { potion.Use(GetComponent<PlayerHealth>()); break; }
|
|
|
|
|
|
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);
|
2026-02-01 15:49:12 +00:00
|
|
|
|
|
|
|
|
|
|
if (playerStats != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
playerStats.weaponDamage = item.Config.BaseDamage;
|
|
|
|
|
|
playerStats.UpdateWeaponWeight(item.Config.RequiredStrength);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ⭐ 무기 장착 즉시 UI 갱신
|
|
|
|
|
|
FindObjectOfType<PlayerStatsUI>()?.UpdateStatTexts();
|
2026-01-29 16:11:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-01 15:49:12 +00:00
|
|
|
|
public void ClearCurrentWeapon()
|
|
|
|
|
|
{
|
|
|
|
|
|
_currentWeapon = null;
|
|
|
|
|
|
if (playerStats != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
playerStats.weaponDamage = 0;
|
|
|
|
|
|
playerStats.ResetWeight();
|
|
|
|
|
|
|
|
|
|
|
|
// ⭐ 무기 제거 즉시 UI 갱신
|
|
|
|
|
|
FindObjectOfType<PlayerStatsUI>()?.UpdateStatTexts();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-29 06:58:38 +00:00
|
|
|
|
}
|