Table of Contents

Method FindNearestEnemy

Namespace
GrindFest
Assembly
GrindFest.dll

FindNearestEnemy(float, float)

Finds the nearest hostile enemy within range that the hero can reach.

public MonsterBehaviour FindNearestEnemy(float maxDistance = 15, float howNear = 2)

Parameters

maxDistance float

Maximum search distance from the hero. Enemies beyond this range will be ignored.

howNear float

How close the hero needs to be able get to the enemy. Most melee attacks require you to stand at distance 2. Used for pathfinding checks.

Returns

MonsterBehaviour

The nearest reachable enemy, or null if no valid enemy is found.

Remarks

The method filters enemies based on several criteria:

  • Must be alive (not dead)
  • Must be within maxDistance
  • Must be hostile to the hero
  • Must be reachable via navigation system
Basic enemy search and attack:
var enemy = FindNearestEnemy(15); // Look for enemies within 15 units
if (enemy != null)
{
    Say($"Found an enemy {enemy.name} at {Vector3.Distance(transform.position, enemy.transform.position)} units away");
}