93 lines
2.7 KiB
C#
93 lines
2.7 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)
|
|
{
|
|
// [MODIFIED] ArrowItem 제거 → ArrowPickup으로 통일
|
|
if (hit.TryGetComponent<ArrowPickup>(out var arrowPickup))
|
|
{
|
|
PickupArrow(arrowPickup);
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// [MODIFIED] ArrowPickup을 직접 처리
|
|
/// 기존: ArrowItem 타입 → 변경: ArrowPickup 타입으로 통일
|
|
/// </summary>
|
|
private void PickupArrow(ArrowPickup arrowPickup)
|
|
{
|
|
if (arrowPickup == null) return;
|
|
|
|
PlayerAttack playerAttack = GetComponent<PlayerAttack>();
|
|
if (playerAttack != null)
|
|
{
|
|
// ArrowPickup.Pickup() 내부에서
|
|
// playerAttack.SetCurrentArrow(ArrowData)를 호출합니다
|
|
arrowPickup.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;
|
|
}
|
|
|
|
FindObjectOfType<PlayerStatsUI>()?.UpdateStatTexts();
|
|
}
|
|
|
|
public void ClearCurrentWeapon()
|
|
{
|
|
_currentWeapon = null;
|
|
if (playerStats != null)
|
|
{
|
|
playerStats.weaponDamage = 0;
|
|
FindObjectOfType<PlayerStatsUI>()?.UpdateStatTexts();
|
|
}
|
|
|
|
// [NEW] 무기 해제 시 화살도 초기화
|
|
PlayerAttack playerAttack = GetComponent<PlayerAttack>();
|
|
if (playerAttack != null)
|
|
{
|
|
playerAttack.ResetArrow();
|
|
}
|
|
}
|
|
} |