171 lines
5.7 KiB
C#
171 lines
5.7 KiB
C#
using UnityEngine;
|
||
|
||
namespace Beyond
|
||
{
|
||
public class DestinationPoint : MonoBehaviour
|
||
{
|
||
[Header("References")]
|
||
[SerializeField] private DestinationPoint nextPoint; // Nast<73>pny punkt docelowy
|
||
[SerializeField] private Collider triggerCollider; // Collider, kt<6B>ry wyzwala zmian<61> punktu
|
||
[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("Settings")]
|
||
[SerializeField] private bool activateOnStart = true;
|
||
[SerializeField] private bool switchOnParentDeactivation = false; // Czy prze<7A><65>cza<7A> na nast<73>pny punkt, gdy obiekt nadrz<72>dny jest dezaktywowany
|
||
|
||
private bool isActive = false; // Czy punkt jest aktywny
|
||
private bool isDestroyed = false;
|
||
private bool wasParentActive = true;
|
||
|
||
//private void OnEnable()
|
||
//{
|
||
// Upewnij si<73>, <20>e widoczno<6E><6F> jest poprawnie ustawiona zanim wszystko si<73> zainicjalizuje
|
||
// UpdateVisibility();
|
||
//}
|
||
|
||
private void Awake()
|
||
{
|
||
// Upewnij si<73>, <20>e collider jest ustawiony jako trigger
|
||
if (triggerCollider != null)
|
||
{
|
||
triggerCollider.isTrigger = true;
|
||
}
|
||
|
||
// Upewnij si<73>, <20>e audioSource jest przypisany
|
||
if (audioSource == null)
|
||
{
|
||
audioSource = gameObject.AddComponent<AudioSource>();
|
||
}
|
||
|
||
// Sprawd<77>, czy obiekt nadrz<72>dny jest aktywny na pocz<63>tku
|
||
if (switchOnParentDeactivation && transform.parent != null)
|
||
{
|
||
wasParentActive = transform.parent.gameObject.activeInHierarchy;
|
||
}
|
||
}
|
||
/*
|
||
|
||
private void Update()
|
||
{
|
||
// Sprawd<77>, czy obiekt nadrz<72>dny zmieni<6E> sw<73>j stan
|
||
if (switchOnParentDeactivation && transform.parent != null)
|
||
{
|
||
bool isParentActive = transform.parent.gameObject.activeInHierarchy;
|
||
if (wasParentActive && !isParentActive)
|
||
{
|
||
// Obiekt nadrz<72>dny zosta<74> dezaktywowany
|
||
HandleParentDeactivated();
|
||
}
|
||
wasParentActive = isParentActive;
|
||
}
|
||
}
|
||
*/
|
||
|
||
private void OnTriggerEnter(Collider other)
|
||
{
|
||
// Zak<61>adamy, <20>e gracz ma tag "Player"
|
||
if (isActive && other.CompareTag("Player"))
|
||
{
|
||
// Odtw<74>rz d<>wi<77>k, je<6A>li jest przypisany
|
||
if (destinationSound != null && audioSource != null)
|
||
{
|
||
audioSource.PlayOneShot(destinationSound);
|
||
}
|
||
|
||
// Prze<7A><65>cz na nast<73>pny punkt
|
||
//DestinationTargetManager.Instance.SwitchToNextPoint(nextPoint);
|
||
|
||
// Dezaktywuj ten punkt
|
||
Deactivate();
|
||
}
|
||
}
|
||
|
||
private void OnEnable()
|
||
{
|
||
// Aktywuj punkt, gdy skrypt jest w<><77>czony
|
||
if (activateOnStart)
|
||
Activate();
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
|
||
// Dezaktywuj punkt, gdy skrypt jest wy<77><79>czony
|
||
Deactivate();
|
||
}
|
||
/*
|
||
// Funkcja sprawdzaj<61>ca, czy obiekt nadrz<72>dny jest aktywny i czy wska<6B>nik powinien by<62> widoczny
|
||
private void UpdateVisibility()
|
||
{
|
||
if (isActive && IsParentActive() && DestinationTargetManager.Instance != null)
|
||
{
|
||
DestinationTargetManager.Instance.SetTargetVisibility(true);
|
||
}
|
||
else if (DestinationTargetManager.Instance != null)
|
||
{
|
||
DestinationTargetManager.Instance.SetTargetVisibility(false);
|
||
}
|
||
}
|
||
|
||
// Sprawdza, czy obiekt nadrz<72>dny jest aktywny
|
||
private bool IsParentActive()
|
||
{
|
||
return transform.parent == null || transform.parent.gameObject.activeInHierarchy;
|
||
}
|
||
*/
|
||
|
||
public void Activate()
|
||
{
|
||
if (!isActive)
|
||
{
|
||
isActive = true;
|
||
if (triggerCollider != null)
|
||
{
|
||
triggerCollider.enabled = true;
|
||
}
|
||
Compass.Instance.AddQuestMarker(transform, null);
|
||
}
|
||
}
|
||
|
||
public void Deactivate()
|
||
{
|
||
if (isActive)
|
||
{
|
||
isActive = false;
|
||
if (triggerCollider != null)
|
||
{
|
||
triggerCollider.enabled = false;
|
||
}
|
||
Compass.Instance.RemoveQuestMarker(transform);
|
||
if (nextPoint)
|
||
{
|
||
nextPoint.Activate();
|
||
}
|
||
|
||
// Ukryj wska<6B>nik, gdy skrypt jest wy<77><79>czony
|
||
//if (DestinationTargetManager.Instance != null)
|
||
//{
|
||
// DestinationTargetManager.Instance.SetTargetVisibility(false);
|
||
// DestinationTargetManager.Instance.SwitchToNextPoint(nextPoint);
|
||
//}
|
||
}
|
||
}
|
||
|
||
/*
|
||
// Funkcja wywo<77>ywana, gdy obiekt nadrz<72>dny zostaje dezaktywowany
|
||
private void HandleParentDeactivated()
|
||
{
|
||
if (switchOnParentDeactivation && !isDestroyed)
|
||
{
|
||
isDestroyed = true;
|
||
// Prze<7A><65>cz na nast<73>pny punkt, je<6A>li obiekt nadrz<72>dny zosta<74> dezaktywowany
|
||
DestinationTargetManager.Instance.SwitchToNextPoint(nextPoint);
|
||
// Dezaktywuj ten punkt
|
||
Deactivate();
|
||
}
|
||
}
|
||
*/
|
||
}
|
||
}
|