69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
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<ArrowItem>(out var arrowItem))
|
|
{
|
|
PickupArrow(arrowItem);
|
|
break;
|
|
}
|
|
|
|
if (hit.TryGetComponent<EquippableItem>(out var item))
|
|
{
|
|
// ✨ [수정] 힘 제한 없이 무조건 습득 가능하도록 변경
|
|
EquipWeapon(item);
|
|
break;
|
|
}
|
|
|
|
if (hit.TryGetComponent<HealthPotion>(out var potion)) { potion.Use(GetComponent<PlayerHealth>()); break; }
|
|
if (hit.TryGetComponent<HealthAltar>(out var altar)) { altar.Use(GetComponent<PlayerHealth>()); break; }
|
|
}
|
|
}
|
|
|
|
private void PickupArrow(ArrowItem arrowItem)
|
|
{
|
|
if (arrowItem == null) return;
|
|
PlayerAttack playerAttack = GetComponent<PlayerAttack>();
|
|
if (playerAttack != null) arrowItem.Pickup(playerAttack);
|
|
}
|
|
|
|
private void EquipWeapon(EquippableItem item)
|
|
{
|
|
if (_currentWeapon != null) _currentWeapon.OnDropped(transform.forward);
|
|
_currentWeapon = item;
|
|
_currentWeapon.OnPickedUp(handSlot);
|
|
|
|
if (playerStats != null)
|
|
{
|
|
playerStats.weaponDamage = item.Config.BaseDamage;
|
|
// ✨ [제거] UpdateWeaponWeight 호출 삭제
|
|
}
|
|
|
|
FindObjectOfType<PlayerStatsUI>()?.UpdateStatTexts();
|
|
}
|
|
|
|
public void ClearCurrentWeapon()
|
|
{
|
|
_currentWeapon = null;
|
|
if (playerStats != null)
|
|
{
|
|
playerStats.weaponDamage = 0;
|
|
// ✨ [제거] ResetWeight 호출 삭제
|
|
FindObjectOfType<PlayerStatsUI>()?.UpdateStatTexts();
|
|
}
|
|
}
|
|
} |