Projext/Assets/5.TestScript/PlayerInteraction.cs

47 lines
1.7 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()
{
// 1. 주변에 아이템이 있는지 확인합니다.
Collider[] hits = Physics.OverlapSphere(transform.position, interactRange, itemLayer);
foreach (var hit in hits)
{
if (hit.TryGetComponent<EquippableItem>(out var item))
{
// 2. 힘(Strength) 조건이 맞는지 체크합니다.
if (playerStats.Strength >= item.Config.RequiredStrength)
{
// 3. 이미 무기를 들고 있다면 바닥에 버립니다.
if (_currentWeapon != null) _currentWeapon.OnDropped(transform.forward);
// 4. 새로운 무기를 장착합니다.
_currentWeapon = item;
_currentWeapon.OnPickedUp(handSlot);
// ⭐ [추가] 무기를 줍는 순간 황금빛 하이라이트를 끕니다.
if (item.TryGetComponent<ItemHighlight>(out var highlight))
{
highlight.StopHighlight();
}
playerStats.UpdateWeaponWeight(item.Config.RequiredStrength);
break;
}
}
}
}
public void ClearCurrentWeapon() => _currentWeapon = null;
}