using UnityEngine; using Unheimlich.Core.Events; namespace Unheimlich.Features.Hallucination { /// /// Drives the HallucinationManager when its GameEventTrigger fires. /// Can increase sanity, fire a discrete HallucinationEvent, or both. /// Compose a GameEventTrigger on the same GameObject to control the firing condition /// (OnStart, OnEnable, delay, once-flag, external call via UnityEvent, etc.). /// [RequireComponent(typeof(GameEventTrigger))] public class HallucinationTrigger : MonoBehaviour { [Header("Sanity")] [Tooltip("Amount of sanity to add when this trigger fires (0 = no change)")] [SerializeField, Range(0f, 1f)] private float _insanityAmount = 0f; [Header("Hallucination Event")] [Tooltip("Optional discrete hallucination event to fire (ghost word, vision flash, etc.)")] [SerializeField] private HallucinationEvent _hallucinationEvent; [Header("Debug")] [SerializeField] private bool _debugMode; private GameEventTrigger _eventTrigger; private void Awake() { _eventTrigger = GetComponent(); _eventTrigger.OnTriggered += Trigger; } private void OnDestroy() { if (_eventTrigger != null) _eventTrigger.OnTriggered -= Trigger; } /// /// Fires the hallucination effect. Can be called directly from external scripts or UnityEvents. /// public void Trigger() { if (HallucinationManager.Instance == null) { Debug.LogError("[HallucinationTrigger] HallucinationManager not found in scene!", this); return; } if (_insanityAmount > 0f) { HallucinationManager.Instance.AddInsanity(_insanityAmount); if (_debugMode) Debug.Log($"[HallucinationTrigger] Added {_insanityAmount:F2} insanity. New sanity: {HallucinationManager.Instance.SanityLevel:F2}", this); } if (_hallucinationEvent != null) { HallucinationManager.Instance.TriggerHallucinationEvent(_hallucinationEvent); if (_debugMode) Debug.Log($"[HallucinationTrigger] Fired event: {_hallucinationEvent.Label}", this); } } } }