Files
beyond/Assets/Scripts/DestinationTargetManager.cs

100 lines
2.8 KiB
C#
Raw Blame History

using UnityEngine;
namespace Beyond
{
public class DestinationTargetManager : MonoBehaviour
{
public static DestinationTargetManager Instance;
[Header("UI Elements")]
[SerializeField] private NavigationIndicator navigationIndicator;
[Header("Audio")]
[SerializeField] private AudioClip destinationSound; // D<>wi<77>k do odtworzenia
[SerializeField] private AudioSource audioSource; // <20>r<EFBFBD>d<EFBFBD>o d<>wi<77>ku
[Header("Initial Target")]
[SerializeField] private DestinationPoint initialTarget; // Pocz<63>tkowy punkt docelowy
private DestinationPoint currentTarget;
private void Awake()
{
if (Instance == null)
{
Instance = this;
//DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
private void Start()
{
// Ustaw pocz<63>tkowy cel, ale nie aktywuj go od razu
SetInitialTarget(initialTarget);
SetTargetVisibility(false); // Pocz<63>tkowy cel jest niewidoczny na pocz<63>tku
}
public void SwitchToNextPoint(DestinationPoint nextPoint)
{
if (nextPoint == null) return;
// Dezaktywuj obecny cel
if (currentTarget != null)
{
currentTarget.Deactivate();
}
// Prze<7A><65>cz na nast<73>pny punkt
currentTarget = nextPoint;
// Ustaw nowy cel na wska<6B>niku
if (navigationIndicator != null)
{
navigationIndicator.SetTargetTransform(currentTarget.transform);
}
// Aktywuj nowy punkt
currentTarget.Activate();
// Odtw<74>rz d<>wi<77>k, je<6A>li jest przypisany
if (destinationSound != null && audioSource != null)
{
audioSource.PlayOneShot(destinationSound);
}
}
public void SetInitialTarget(DestinationPoint target)
{
if (target == null) return;
currentTarget = target;
// Ustaw pocz<63>tkowy cel na wska<6B>niku, ale go nie aktywuj
if (navigationIndicator != null)
{
navigationIndicator.SetTargetTransform(currentTarget.transform);
}
}
// Nowa metoda do ustawiania widoczno<6E>ci celu
public void SetTargetVisibility(bool isVisible)
{
if (navigationIndicator != null)
{
if (isVisible)
{
navigationIndicator.SetTargetTransform(currentTarget.transform);
}
else
{
navigationIndicator.Deactivate();
}
}
}
}
}