using UnityEngine; /// /// Interaction requirement that checks if the follower is holding a specific required item. /// [RequireComponent(typeof(Interactable))] public class RequiresItemBehavior : InteractionRequirementBase { [Header("Required Item")] public PickupItemData requiredItem; /// /// Attempts to interact, succeeds only if the follower is holding the required item. /// /// The follower attempting the interaction. /// True if the interaction was successful, false otherwise. public override bool TryInteract(FollowerController follower) { var heldItem = follower.CurrentlyHeldItem; if (heldItem == requiredItem) { OnSuccess?.Invoke(); return true; } else { string requiredName = requiredItem != null ? requiredItem.itemName : "required item"; if (heldItem == null) { DebugUIMessage.Show($"You need {requiredName} to interact."); } else { string heldName = heldItem.itemName ?? "an item"; DebugUIMessage.Show($"You need {requiredName}, but you are holding {heldName}."); } OnFailure?.Invoke(); return false; } } }