Files
TopDown/Assets/Scripts/Quests/LocationObjectiveTrigger.cs

39 lines
1.1 KiB
C#
Raw Permalink Normal View History

using UnityEngine;
namespace Quests
{
[RequireComponent(typeof(Collider))]
public class LocationObjectiveTrigger : MonoBehaviour
{
[Tooltip("The Target ID of the ReachLocation objective.")]
[SerializeField] private string locationID;
[Tooltip("Only trigger when the collider tagged with this tag enters. Default: 'Player'")]
[SerializeField] private string playerTag = "Player";
[Tooltip("If true, this trigger object disables itself after firing once.")]
[SerializeField] private bool triggerOnce = true;
private bool hasTriggered = false;
private void OnTriggerEnter(Collider other)
{
if (hasTriggered && triggerOnce) return;
if (other.CompareTag(playerTag))
{
if (QuestManager.Instance != null)
{
QuestManager.Instance.ReportLocationReached(locationID);
hasTriggered = true;
if (triggerOnce)
{
gameObject.SetActive(false);
}
}
}
}
}
}