Files
Stair_Horror/Assets/Scripts/StaircaseScare.cs
2025-12-01 16:30:54 +00:00

41 lines
1.2 KiB
C#

using UnityEngine;
public class StaircaseScare : MonoBehaviour
{
[Header("Audio Scares")]
public AudioSource audioSource;
public AudioClip[] scarySounds; // Drag footsteps, whispers, name calling here
[Header("Mechanics")]
[Range(0f, 100f)] public float chanceToRelight = 50f; // 50% chance a light turns on
private bool hasTriggered = false; // Ensure it only happens once per climb
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player") && !hasTriggered)
{
// 1. Play a random scary sound
if (scarySounds.Length > 0)
{
AudioClip clip = scarySounds[Random.Range(0, scarySounds.Length)];
audioSource.PlayOneShot(clip);
}
// 2. Chance to turn a light back on downstairs
if (Random.Range(0f, 100f) < chanceToRelight)
{
GameManager.Instance.SpookyRelightEvent();
}
// Reset trigger after a delay so they can be scared again if they go back down
Invoke("ResetTrigger", 10f);
hasTriggered = true;
}
}
void ResetTrigger()
{
hasTriggered = false;
}
}