38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using UnityEngine;
|
|
using Unheimlich.Core.Audio;
|
|
|
|
namespace Unheimlich.Features.Hallucination
|
|
{
|
|
/// <summary>
|
|
/// Fires a hallucination effect when a specific AudioSource plays, finishes, or reaches a timestamp.
|
|
/// Call OnAudioPlay() from whatever drives the AudioSource to start monitoring.
|
|
/// </summary>
|
|
public class HallucinationOnAudio : AudioTriggerBase
|
|
{
|
|
[Header("Hallucination Payload")]
|
|
[Tooltip("Amount of insanity to add when this fires (0 = no change)")]
|
|
[SerializeField, Range(0f, 1f)] private float _insanityAmount = 0f;
|
|
|
|
[Tooltip("Optional discrete hallucination event to fire")]
|
|
[SerializeField] private HallucinationEvent _hallucinationEvent;
|
|
|
|
protected override void Execute()
|
|
{
|
|
if (HallucinationManager.Instance == null)
|
|
{
|
|
Debug.LogError("[HallucinationOnAudio] HallucinationManager not found!", this);
|
|
return;
|
|
}
|
|
|
|
if (_insanityAmount > 0f)
|
|
HallucinationManager.Instance.AddInsanity(_insanityAmount);
|
|
|
|
if (_hallucinationEvent != null)
|
|
HallucinationManager.Instance.TriggerHallucinationEvent(_hallucinationEvent);
|
|
|
|
if (_debugMode)
|
|
Debug.Log($"[HallucinationOnAudio] Fired on '{_fireCondition}'. Sanity: {HallucinationManager.Instance.SanityLevel:F2}", this);
|
|
}
|
|
}
|
|
}
|