2026-06-19 UI, UI로직
This commit is contained in:
52
Assets/My project/Memory Scripts/UI/MemoryPiecePickup.cs
Normal file
52
Assets/My project/Memory Scripts/UI/MemoryPiecePickup.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class MemoryPiecePickup : MonoBehaviour
|
||||
{
|
||||
[Header("Reference")]
|
||||
[SerializeField] private MemoryProgressManager memoryProgressManager;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private int amount = 1;
|
||||
[SerializeField] private bool destroyAfterPickup = true;
|
||||
[SerializeField] private bool autoFindManager = true;
|
||||
[SerializeField] private string playerTag = "Player";
|
||||
|
||||
[Header("Events")]
|
||||
public UnityEvent onPickedUp;
|
||||
|
||||
private bool pickedUp;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (memoryProgressManager == null && autoFindManager)
|
||||
memoryProgressManager = FindFirstObjectByType<MemoryProgressManager>();
|
||||
}
|
||||
|
||||
public void PickUp()
|
||||
{
|
||||
if (pickedUp)
|
||||
return;
|
||||
|
||||
pickedUp = true;
|
||||
|
||||
if (memoryProgressManager != null)
|
||||
memoryProgressManager.AddMemoryPiece(amount);
|
||||
else
|
||||
Debug.LogWarning("[MemoryPiecePickup] MemoryProgressManager가 연결되지 않았습니다.");
|
||||
|
||||
onPickedUp?.Invoke();
|
||||
|
||||
if (destroyAfterPickup)
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (pickedUp)
|
||||
return;
|
||||
|
||||
if (other.CompareTag(playerTag))
|
||||
PickUp();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user