2026-04-29 음식섭취 - 포만감 연동
This commit is contained in:
@@ -19,13 +19,11 @@ public class TastingSample : MonoBehaviour
|
||||
[SerializeField] private bool _requireGrabbed = true;
|
||||
|
||||
private XRGrabInteractable _grab;
|
||||
private AudioSource _sfxSource;
|
||||
private bool _consumed;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_grab = GetComponent<XRGrabInteractable>();
|
||||
_sfxSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -42,19 +40,32 @@ private void Update()
|
||||
|
||||
private void Consume()
|
||||
{
|
||||
var interactor = _grab.firstInteractorSelecting as MonoBehaviour;
|
||||
|
||||
_consumed = true;
|
||||
|
||||
// 손에서 강제 해제 (잡혀있던 상태로 Destroy되면 XRI 경고)
|
||||
if (_grab != null && _grab.isSelected && _grab.interactionManager != null)
|
||||
_grab.interactionManager.CancelInteractableSelection((UnityEngine.XR.Interaction.Toolkit.Interactables.IXRSelectInteractable)_grab);
|
||||
|
||||
// SFX 재생 후 파괴 (사운드 길이 고려)
|
||||
var sfx = _foodData.EatSfx;
|
||||
if (sfx != null)
|
||||
PlayerHunger hunger = interactor != null ? interactor.GetComponentInParent<PlayerHunger>() : null;
|
||||
if(hunger != null)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(sfx, transform.position);
|
||||
hunger.Eat(_foodData.HungerRestoreAmount);
|
||||
}
|
||||
|
||||
// VFX/SFX는 임시 오브젝트로 분리 재생 — 본체가 즉시 Destroy되어도 끊기지 않음
|
||||
if (_foodData.EatVfx != null)
|
||||
{
|
||||
var vfx = Instantiate(_foodData.EatVfx, transform.position, Quaternion.identity);
|
||||
vfx.Play();
|
||||
var main = vfx.main;
|
||||
Destroy(vfx.gameObject, main.duration + main.startLifetime.constantMax);
|
||||
}
|
||||
|
||||
if (_foodData.EatSfx != null)
|
||||
AudioSource.PlayClipAtPoint(_foodData.EatSfx, transform.position);
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user