Method FindNearestInteractive
- Namespace
- GrindFest
- Assembly
- GrindFest.dll
FindNearestInteractive(string, string, string, float)
Finds the nearest interactive object (like chests or shrines) that matches the name criteria.
public static InteractiveBehaviour FindNearestInteractive(string name1 = "", string name2 = null, string name3 = null, float maxDistance = 15)
Parameters
name1stringPrimary name to search for. Object name must contain this string. If empty, matches any name.
name2stringOptional secondary name to search for. If provided, object name must contain either this or name1.
name3stringOptional tertiary name to search for. If provided, object name must contain either this, name2, or name1.
maxDistancefloatMaximum search distance from the hero. Defaults to 15 units.
Returns
- InteractiveBehaviour
The nearest InteractiveBehaviour that matches the criteria, or null if no matching object is found.
Remarks
This method searches for objects on the Interactable layer, which includes:
- Chests containing loot
- Shrines providing buffs
- NPCs for trading and dialogue
var chest = Hero.FindNearestInteractive("Chest");
if (chest != null)
{
if (Hero.InteractWith(chest))
{
Hero.Say("Found and opened a chest!");
}
}var shrine = Hero.FindNearestInteractive("Shrine");
if (shrine != null)
{
Hero.InteractWith(shrine);
Hero.Say($"Used {shrine.name}!");
}FindNearestInteractive(Predicate<InteractiveBehaviour>, float)
Finds the nearest interactive object (like chests or shrines) that matches the name criteria.
public static InteractiveBehaviour FindNearestInteractive(Predicate<InteractiveBehaviour> predicate, float maxDistance = 15)
Parameters
predicatePredicate<InteractiveBehaviour>maxDistancefloatMaximum search distance from the hero. Defaults to 15 units.
Returns
- InteractiveBehaviour
The nearest InteractiveBehaviour that matches the criteria, or null if no matching object is found.
Remarks
This method searches for objects on the Interactable layer, which includes:
- Chests containing loot
- Shrines providing buffs
- NPCs for trading and dialogue
var chest = FindNearestInteractive("Chest");
if (chest != null)
{
if (InteractWith(chest))
{
Say("Found and opened a chest!");
}
}var shrine = FindNearestInteractive("Shrine");
if (shrine != null)
{
InteractWith(shrine);
Say($"Used {shrine.name}!");
}