Files
fgj-26/Scripts/Helpers/Helpers.cs
T
2026-01-31 23:25:02 +02:00

26 lines
693 B
C#

using System;
using Godot;
namespace fgj26.Scripts.Helpers;
public static class Helpers
{
public static Node2D GetClosest(Node2D from, Node2D[] targets)
{
ArgumentNullException.ThrowIfNull(from);
ArgumentNullException.ThrowIfNull(targets);
if (targets.Length == 0) throw new ArgumentNullException(nameof(targets));
float dist = float.PositiveInfinity;
Node2D closest = null;
foreach (var t in targets)
{
var td = t.GlobalPosition.DistanceTo(from.GlobalPosition);
if (td < dist)
{
dist = td;
closest = t;
}
}
return closest;
}
}