Files
Stair_Horror/Assets/Scripts/GameManager.cs

87 lines
2.5 KiB
C#

using UnityEngine;
using System.Collections.Generic;
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
public List<LightSwitch> allSwitches = new List<LightSwitch>();
[Header("Front Door Event")]
public FrontDoorEvent frontDoor; // Assigned automatically by the door script
public int lightsOffToTriggerDoor = 4; // Event happens after 4 lights turned off
private int lightsTurnedOffCounter = 0;
void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
}
public void RegisterSwitch(LightSwitch sw)
{
if (!allSwitches.Contains(sw)) allSwitches.Add(sw);
}
public void CheckLights()
{
int currentOffCount = 0;
foreach (LightSwitch sw in allSwitches)
{
if (!sw.isLightOn) currentOffCount++;
}
// Check if we hit the threshold for the doorbell
if (currentOffCount >= lightsOffToTriggerDoor && frontDoor != null)
{
frontDoor.TriggerEvent();
// Set to null so it doesn't trigger twice
frontDoor = null;
}
}
public void SpookyRelightEvent()
{
// Find all switches that are currently OFF
List<LightSwitch> offSwitches = new List<LightSwitch>();
foreach (LightSwitch sw in allSwitches)
{
if (!sw.isLightOn) offSwitches.Add(sw);
}
// If we found any off switches, turn one back on randomly
if (offSwitches.Count > 0)
{
LightSwitch target = offSwitches[Random.Range(0, offSwitches.Count)];
target.ForceLightOn();
Debug.Log("A light turned back on!");
}
}
public bool AreAnyLightsOn()
{
foreach (LightSwitch sw in allSwitches)
{
if (sw.isLightOn) return true;
}
return false;
}
public void TriggerNightmareMode()
{
Debug.Log("NOBODY IS HOME. NIGHTMARE MODE ACTIVE.");
foreach(LightSwitch sw in allSwitches)
{
// 1. Turn all lights back ON
sw.ForceLightOn();
// 2. Increase Difficulty (59% increase)
// If chance was 0.1 (10%), it becomes roughly 0.16
sw.malfunctionChance += (sw.malfunctionChance * 0.59f);
// Cap it so it's not impossible (e.g., max 50% fail rate)
if (sw.malfunctionChance > 0.5f) sw.malfunctionChance = 0.5f;
// 3. Make random scares more frequent
sw.subsequentEventChance += 10f;
}
}
}