Continued working on the lights, set up playable version and turn trap at the end of the stairs. Working on making stairs feel longer.

This commit is contained in:
2025-12-03 17:23:18 +00:00
parent 732a2577c2
commit e0c93be280
67 changed files with 29354 additions and 534 deletions

View File

@@ -0,0 +1,119 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class StaircaseCurse : MonoBehaviour
{
[Header("Don't Look Back Settings")]
[Range(-1f, 1f)] public float killThreshold = -0.2f;
public GameObject blackScreenPanel;
[Header("Spooky Audio System")]
[Tooltip("Drag empty GameObjects with AudioSources from around the map here")]
public AudioSource[] environmentalSources;
public AudioClip[] scaryClips; // Whispers, footsteps, wood creaks
[Tooltip("Minimum seconds between random noises")]
public float minSoundDelay = 2f;
[Tooltip("Maximum seconds between random noises")]
public float maxSoundDelay = 5f;
// Internal State
private bool playerOnStairs = false;
private Transform playerTransform;
private bool isDead = false;
private float soundTimer;
void Start()
{
// Initialize timer
soundTimer = Random.Range(minSoundDelay, maxSoundDelay);
}
void Update()
{
if (isDead || !playerOnStairs) return;
// 1. CHECK LIGHTS & FACING DIRECTION
// If lights are OFF, the curse is active
if (GameManager.Instance != null && !GameManager.Instance.AreAnyLightsOn())
{
CheckPlayerFacing();
// 2. HANDLE RANDOM AUDIO
HandleAudio();
}
}
void HandleAudio()
{
soundTimer -= Time.deltaTime;
if (soundTimer <= 0)
{
PlayRandomSound();
// Reset timer
soundTimer = Random.Range(minSoundDelay, maxSoundDelay);
}
}
void PlayRandomSound()
{
if (environmentalSources.Length == 0 || scaryClips.Length == 0) return;
// 1. Pick a random sound
AudioClip clip = scaryClips[Random.Range(0, scaryClips.Length)];
// 2. Pick a random location (Source)
AudioSource source = environmentalSources[Random.Range(0, environmentalSources.Length)];
// 3. Play
source.PlayOneShot(clip);
Debug.Log($"Played sound from: {source.name}");
}
void CheckPlayerFacing()
{
// (Same logic as before)
Vector3 stairsDir = transform.forward;
Vector3 playerDir = playerTransform.forward;
stairsDir.y = 0; playerDir.y = 0;
stairsDir.Normalize(); playerDir.Normalize();
if (Vector3.Dot(stairsDir, playerDir) < killThreshold)
{
TriggerGameOver();
}
}
void TriggerGameOver()
{
isDead = true;
if (blackScreenPanel != null) blackScreenPanel.SetActive(true);
// Disable controls
if (playerTransform.GetComponent<PlayerController>())
playerTransform.GetComponent<PlayerController>().enabled = false;
Invoke("RestartLevel", 3f);
}
void RestartLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
playerOnStairs = true;
playerTransform = other.transform;
// Reset timer so a sound doesn't play INSTANTLY upon entering
soundTimer = Random.Range(minSoundDelay, maxSoundDelay);
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player")) playerOnStairs = false;
}
}