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:
75
Assets/Scripts/WinZone.cs
Normal file
75
Assets/Scripts/WinZone.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI; // Needed for UI
|
||||
using System.Collections;
|
||||
using TMPro; // Optional, if you want "Sweet Dreams" text
|
||||
|
||||
public class WinZone : MonoBehaviour
|
||||
{
|
||||
[Header("UI Settings")]
|
||||
public GameObject blackScreenPanel;
|
||||
public TextMeshProUGUI winText; // Assign a TMP text that says "Sweet Dreams"
|
||||
public float fadeDuration = 3f;
|
||||
|
||||
[Header("Audio")]
|
||||
public AudioSource playerAudioSource; // To stop footsteps/breathing
|
||||
public AudioClip winSound; // Gentle lullaby or peaceful sound
|
||||
|
||||
private bool hasWon = false;
|
||||
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player") && !hasWon)
|
||||
{
|
||||
// Only win if lights are OFF (optional check)
|
||||
if (GameManager.Instance != null && !GameManager.Instance.AreAnyLightsOn())
|
||||
{
|
||||
StartCoroutine(WinSequence(other.gameObject));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator WinSequence(GameObject player)
|
||||
{
|
||||
hasWon = true;
|
||||
Debug.Log("Player reached the top! Winning...");
|
||||
|
||||
// 1. Disable Player Controls immediately
|
||||
PlayerController pc = player.GetComponent<PlayerController>();
|
||||
if (pc != null) pc.enabled = false;
|
||||
|
||||
// 2. Disable the Staircase Curse so they don't die while fading
|
||||
StaircaseCurse curse = FindObjectOfType<StaircaseCurse>();
|
||||
if (curse != null) curse.enabled = false;
|
||||
|
||||
// 3. Play Win Sound
|
||||
if (playerAudioSource != null && winSound != null)
|
||||
playerAudioSource.PlayOneShot(winSound);
|
||||
|
||||
// 4. Fade to Black
|
||||
if (blackScreenPanel != null)
|
||||
{
|
||||
blackScreenPanel.SetActive(true);
|
||||
CanvasGroup cg = blackScreenPanel.GetComponent<CanvasGroup>();
|
||||
|
||||
// If no CanvasGroup exists, add one
|
||||
if (cg == null) cg = blackScreenPanel.AddComponent<CanvasGroup>();
|
||||
|
||||
float timer = 0f;
|
||||
while (timer < fadeDuration)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
cg.alpha = timer / fadeDuration; // Fade from 0 to 1
|
||||
yield return null;
|
||||
}
|
||||
cg.alpha = 1f;
|
||||
}
|
||||
|
||||
// 5. Show Text
|
||||
if (winText != null) winText.gameObject.SetActive(true);
|
||||
|
||||
// 6. Quit Game (or wait and load menu)
|
||||
yield return new WaitForSeconds(3f);
|
||||
Debug.Log("Quitting Application...");
|
||||
Application.Quit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user