using UnityEngine;
namespace UI.Tracking
{
///
/// Marks a GameObject as the source point for distance calculations in the tracking system.
/// Typically attached to the player or camera. Only one should be active at a time.
///
public class TrackingDistanceSource : MonoBehaviour
{
private static TrackingDistanceSource _instance;
///
/// The currently active distance source (typically the player)
///
public static TrackingDistanceSource Instance => _instance;
///
/// The world position of this distance source
///
public Vector3 WorldPosition => transform.position;
private void OnEnable()
{
// Set as the active instance
if (_instance != null && _instance != this)
{
Debug.LogWarning($"[TrackingDistanceSource] Multiple distance sources detected. Overwriting previous instance ({_instance.name}) with {name}");
}
_instance = this;
}
private void OnDisable()
{
// Clear instance if this was the active one
if (_instance == this)
{
_instance = null;
}
}
}
}