using UnityEngine; /// /// Utility class for proximity and distance-based calculations. /// Centralizes common distance checking logic used throughout the game. /// public static class ProximityUtility { /// /// Check if two objects are within a specified distance /// public static bool IsWithinDistance(Vector3 from, Vector3 to, float distance) { return Vector3.Distance(from, to) <= distance; } /// /// Check if two Transform objects are within a specified distance /// public static bool IsWithinDistance(Transform from, Transform to, float distance) { if (from == null || to == null) return false; return IsWithinDistance(from.position, to.position, distance); } /// /// Check if GameObject is within a specified distance /// public static bool IsWithinDistance(GameObject from, GameObject to, float distance) { if (from == null || to == null) return false; return IsWithinDistance(from.transform.position, to.transform.position, distance); } /// /// Get the distance between two positions /// public static float GetDistance(Vector3 from, Vector3 to) { return Vector3.Distance(from, to); } /// /// Get the distance between two Transform objects /// public static float GetDistance(Transform from, Transform to) { if (from == null || to == null) return float.MaxValue; return GetDistance(from.position, to.position); } /// /// Get the distance between two GameObjects /// public static float GetDistance(GameObject from, GameObject to) { if (from == null || to == null) return float.MaxValue; return GetDistance(from.transform.position, to.transform.position); } /// /// Check if object is in range and handle both close and far cases /// public static bool CheckRange(Vector3 from, Vector3 to, float minDistance, float maxDistance, out float distance) { distance = GetDistance(from, to); return distance >= minDistance && distance <= maxDistance; } }