using UnityEngine; namespace UnityUtils { public static class Vector2Extensions { /// /// Adds to any x y values of a Vector2 /// public static Vector2 Add(this Vector2 vector2, float x = 0, float y = 0) { return new Vector2(vector2.x + x, vector2.y + y); } /// /// Sets any x y values of a Vector2 /// public static Vector2 With(this Vector2 vector2, float? x = null, float? y = null) { return new Vector2(x ?? vector2.x, y ?? vector2.y); } /// /// Returns a Boolean indicating whether the current Vector2 is in a given range from another Vector2 /// /// The current Vector2 position /// The Vector2 position to compare against /// The range value to compare against /// True if the current Vector2 is in the given range from the target Vector2, false otherwise public static bool InRangeOf(this Vector2 current, Vector2 target, float range) { return (current - target).sqrMagnitude <= range * range; } } }