Files
Ipseity-Demo/Assets/Unheimlich_POC/Scripts/Handlers/DetectiveBoard/ClueUnlockOnInteraction.cs
T

61 lines
1.8 KiB
C#

using UnityEngine;
using Unheimlich.Data.DetectiveBoard;
using Unheimlich.Interactions.Core;
using Unheimlich.Managers;
using Unheimlich.Gameplay.Items;
namespace Unheimlich.Handlers.DetectiveBoard
{
/// <summary>
/// Unlocks a clue when the player interacts with this object.
/// Can work standalone (extends InteractableBase) or piggyback on an existing InspectableItem.
/// </summary>
public class ClueUnlockOnInteraction : InteractableBase
{
[Header("Clue Configuration")]
[Tooltip("The clue to unlock when player interacts")]
[SerializeField] private ClueData _clueToUnlock;
[Tooltip("Only unlock once")]
[SerializeField] private bool _unlockOnlyOnce = true;
private bool _hasUnlocked;
private InspectableItem _inspectableItem;
private void Awake()
{
_inspectableItem = GetComponent<InspectableItem>();
}
public override void Interact()
{
if (_unlockOnlyOnce && _hasUnlocked)
{
if (_inspectableItem != null)
_inspectableItem.Interact();
return;
}
if (_clueToUnlock == null)
{
Debug.LogError("[ClueUnlockOnInteraction] No clue data assigned!");
if (_inspectableItem != null)
_inspectableItem.Interact();
return;
}
if (DetectiveBoardManager.Instance != null)
{
DetectiveBoardManager.Instance.UnlockClue(_clueToUnlock);
_hasUnlocked = true;
}
if (_inspectableItem != null)
{
_inspectableItem.Interact();
}
}
}
}