This commit is contained in:
2026-01-31 23:24:13 +02:00
parent be0c819c8b
commit 12c1360ae7
58 changed files with 1902 additions and 238 deletions
+26
View File
@@ -0,0 +1,26 @@
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;
}
}