Files
AppleHillsProduction/Assets/Scripts/Interactable.cs

59 lines
1.7 KiB
C#
Raw Normal View History

using UnityEngine;
using System;
public class Interactable : MonoBehaviour, ITouchInputConsumer
{
public event Action Interacted;
private ObjectiveStepBehaviour stepBehaviour;
void Awake()
{
stepBehaviour = GetComponent<ObjectiveStepBehaviour>();
}
// Called by InputManager when this interactable is clicked/touched
public void OnTouchPress(Vector2 worldPosition)
{
if (stepBehaviour != null && !stepBehaviour.IsStepUnlocked())
{
DebugUIMessage.Show("Item is not unlocked yet");
Debug.Log("[Puzzles] Tried to interact with locked step: " + gameObject.name);
return;
}
Debug.Log($"[Interactable] OnTouchPress at {worldPosition} on {gameObject.name}");
Interacted?.Invoke();
}
public void OnTouchPosition(Vector2 screenPosition)
{
// Optionally handle drag/move here
}
// Called when the follower arrives at this interactable
public bool OnFollowerArrived(FollowerController follower)
{
var requirements = GetComponents<InteractionRequirementBase>();
if (requirements.Length == 0)
{
// No requirements: allow default pickup
return true;
}
bool anySuccess = false;
foreach (var req in requirements)
{
if (req.TryInteract(follower))
{
anySuccess = true;
break;
}
}
if (!anySuccess)
{
Debug.Log($"[Interactable] No interaction requirements succeeded for {gameObject.name}");
// Optionally trigger a default failure event or feedback here
}
return anySuccess;
}
}