Projext/Assets/Scripts/Player/Interaction/PlayerInteraction.cs

69 lines
2.2 KiB
C#
Raw Normal View History

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-02-06 09:27:08 +00:00
if (hit.TryGetComponent<ArrowItem>(out var arrowItem))
{
PickupArrow(arrowItem);
break;
}
2026-01-29 06:58:38 +00:00
if (hit.TryGetComponent<EquippableItem>(out var item))
{
// ✨ [수정] 힘 제한 없이 무조건 습득 가능하도록 변경
EquipWeapon(item);
break;
2026-01-29 06:58:38 +00:00
}
2026-02-06 09:27:08 +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-02-06 09:27:08 +00:00
private void PickupArrow(ArrowItem arrowItem)
{
if (arrowItem == null) return;
PlayerAttack playerAttack = GetComponent<PlayerAttack>();
if (playerAttack != null) arrowItem.Pickup(playerAttack);
2026-02-06 09:27:08 +00:00
}
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();
}
}
2026-01-29 06:58:38 +00:00
}