Big script cleanup. Remove the examples from Ropes' external package
This commit is contained in:
41
Assets/Scripts/Interactions/RequiresItemBehavior.cs
Normal file
41
Assets/Scripts/Interactions/RequiresItemBehavior.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction requirement that checks if the follower is holding a specific required item.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Interactable))]
|
||||
public class RequiresItemBehavior : InteractionRequirementBase
|
||||
{
|
||||
[Header("Required Item")]
|
||||
public PickupItemData requiredItem;
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to interact, succeeds only if the follower is holding the required item.
|
||||
/// </summary>
|
||||
/// <param name="follower">The follower attempting the interaction.</param>
|
||||
/// <returns>True if the interaction was successful, false otherwise.</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user