60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public static GameManager Instance;
|
|
public List<LightSwitch> allSwitches = new List<LightSwitch>();
|
|
|
|
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()
|
|
{
|
|
bool anyLightsOn = false;
|
|
foreach (LightSwitch sw in allSwitches)
|
|
{
|
|
if (sw.isLightOn) anyLightsOn = true;
|
|
}
|
|
|
|
if (!anyLightsOn)
|
|
{
|
|
Debug.Log("All lights are off. Player can go to bed.");
|
|
// You can enable the "Bed" interaction collider here
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |