using UnityEngine; /// /// Example script showing how to interact with the Quest system /// Attach to objects that trigger quest progression (enemies, items, zones, etc.) /// public class QuestTrigger : MonoBehaviour { [Header("Quest Trigger Settings")] [Tooltip("The quest ID this trigger affects")] public string questId; [Tooltip("How much progress to add when triggered")] public int progressAmount = 1; [Tooltip("Trigger type")] public TriggerType triggerType = TriggerType.OnTriggerEnter; [Tooltip("Tag required to trigger (e.g., 'Player')")] public string requiredTag = "Player"; [Tooltip("Destroy this GameObject after triggering")] public bool destroyAfterTrigger = false; [Tooltip("Only trigger once")] public bool triggerOnce = true; private bool hasTriggered = false; public enum TriggerType { OnTriggerEnter, OnCollisionEnter, Manual } void OnTriggerEnter(Collider other) { if (triggerType == TriggerType.OnTriggerEnter) { TryTrigger(other.gameObject); } } void OnCollisionEnter(Collision collision) { if (triggerType == TriggerType.OnCollisionEnter) { TryTrigger(collision.gameObject); } } /// /// Manually trigger quest progress (call from other scripts) /// public void ManualTrigger(GameObject triggerer = null) { if (triggerType == TriggerType.Manual || triggerType == TriggerType.OnTriggerEnter) { TryTrigger(triggerer); } } void TryTrigger(GameObject triggerer) { // Check if already triggered if (hasTriggered && triggerOnce) return; // Check tag requirement if (triggerer != null && !string.IsNullOrEmpty(requiredTag)) { if (!triggerer.CompareTag(requiredTag)) return; } // Check if QuestManager exists if (QuestManager.Instance == null) { Debug.LogWarning("QuestManager not found in scene.", gameObject); return; } // Check if quest is active if (!QuestManager.Instance.IsQuestActive(questId)) { Debug.Log($"Quest '{questId}' is not active. Cannot progress.", gameObject); return; } // Progress the quest bool progressed = QuestManager.Instance.ProgressQuest(questId, progressAmount); if (progressed) { hasTriggered = true; Debug.Log($"Quest '{questId}' progressed by {progressAmount}", gameObject); // Destroy if configured if (destroyAfterTrigger) { Destroy(gameObject); } } } }